N
Newshound
Hi all,
I'm trying to take a "cvs commit -m" command line with a multi-line
log message and run it inside a Perl script. For instance, trying to
run the command line:
prompt> cvs commit -m"This is a\
? multi-line log message." filename
prompt>
I would be trying to run this inside Perl as:
my $mesg = "\"This is a\\\nmulti-line log message."
RunCommand("cvs commit -m $mesg filename","commit.log");
....
sub RunCommand {
my $Command = shift;
my $Logfile = shift;
open(CMD_PIPE, "$Command |" )
open( LOG, ">$Logfile" )
while ( <CMD_PIPE> ) { print LOG $_; }
close( CMD_PIPE );
close( LOG )
}
There is some other stuff going on in the subroutine for stderr
redirection, skipping the command and just echoing it, etc., but
this captures the main point of the code.
The problem I am having is that this doesn't work correctly; it
always produces malformed log strings. I'm not a Perl jockey,
I know enough to get by, and the extra backslashes for multiple
layers of quoting sometimes confuse me, but I've tried the above
with various numbers of backslashes as well as splitting the
message string up into a concatenation of substrings to isolate
the newline, etc.
I just can't quite seem to find the right code. I'm trying to make
sure that a backslash is present to indicate the multi-line nature
of the message, as well as a newline to actually split the message
onto another line, but what cvs commit receives is not what I intend.
Can someone please help? I'd really appreciate it.
Thanks,
Mike
I'm trying to take a "cvs commit -m" command line with a multi-line
log message and run it inside a Perl script. For instance, trying to
run the command line:
prompt> cvs commit -m"This is a\
? multi-line log message." filename
prompt>
I would be trying to run this inside Perl as:
my $mesg = "\"This is a\\\nmulti-line log message."
RunCommand("cvs commit -m $mesg filename","commit.log");
....
sub RunCommand {
my $Command = shift;
my $Logfile = shift;
open(CMD_PIPE, "$Command |" )
open( LOG, ">$Logfile" )
while ( <CMD_PIPE> ) { print LOG $_; }
close( CMD_PIPE );
close( LOG )
}
There is some other stuff going on in the subroutine for stderr
redirection, skipping the command and just echoing it, etc., but
this captures the main point of the code.
The problem I am having is that this doesn't work correctly; it
always produces malformed log strings. I'm not a Perl jockey,
I know enough to get by, and the extra backslashes for multiple
layers of quoting sometimes confuse me, but I've tried the above
with various numbers of backslashes as well as splitting the
message string up into a concatenation of substrings to isolate
the newline, etc.
I just can't quite seem to find the right code. I'm trying to make
sure that a backslash is present to indicate the multi-line nature
of the message, as well as a newline to actually split the message
onto another line, but what cvs commit receives is not what I intend.
Can someone please help? I'd really appreciate it.
Thanks,
Mike