Perl experts: I need to run shell command from perl using pipe
Hello experts attention need
I am looking to run a unix shell command in perl script but its getting failing due to pipe "|" and semi colon ";" can any one help me to run folloing command in perl script p4 -o $valu | sed -e "s/<xxxx>/zzz/g/\;/s/<ggg>/ffff/g" | p4 change -i above command should run in one shot THANKS IN ADVANCE |
Quote:
Also, did you use Code:
use strict; |
I agree with Sergei. But the real question is why you think it is useful to use perl to launch a shell script that uses sed. Anything sed can do, perl itself can do at least as well.
You can use at least three common methods to run a shell script: backticks, system(), or opened() as a pipe. --- rod |
Quote:
why you think it is useful to use perl to launch a shell script that uses sed??? I am using sed because I was using perforce tool, for this tool the command should chanage descript bye pipe and it replaces the description. p4 -o $valu --> Opening changelist sed -e "s/<xxxx>/zzz/g/\;/s/<ggg>/ffff/g" --> replacing string to opened file p4 change -i --> saving the file what ever descript we given let me know if is there is any other I can do this in perl. I am not an expert in scripting show I am working on Perl its all most done as I mestioned it was failing due to the command after running the scrip I getting following errors. after running script getting folloing errors Global symbol "$thirdvalue" requires explicit package name at Integration.pl line 33. syntax error at Integration.pl line 33, near ""p4 -c change -o $thirdvalue | sed -e "s/<enter description>/Test Merge/g" Integration.pl has too many errors. line 33 code --> my $fifthCommand = "p4 -c change -o $thirdvalue | sed -e "s/<enter description>/Test Merge/g/\;/s/<enter effort>/1/g" | p4 change -i"; Thanks for your time and efforts. |
You seem to be using a variable '$thirdvalue', without any package declaration. It seems to be used as an argument to a command, so it is probably also undefined. Without knowing anything about the logic of your code, my guess is that somewhere earlier in the script, there should probably an assignment to that variable, for instance:
Code:
my $thirdvalue = "whatever"; It may be mainly a matter of personal preference, but I would still not launch sed to do what Perl can already do by itself. Others will no doubt make arguments to the contrary. By the way, your post would be more readable if code was posted in code tags. --- rod. |
Quote:
Code:
open( PERFORCE, "p4 -c change -o $thirdvalue |" ); --- rod. |
Quote:
Quote:
after running script code following errors occured. syntax error at Integration.pl line 37, near "] ~" syntax error at Integration.pl line 38, near "] ~" Missing comma after first argument to open function at Integration.pl line 41, near ""| p4 change -i" )" Execution of Integration.pl aborted due to compilation errors. ------- code on line 37, 38 and 41. 37. foreach my $i ( 0 .. (scalar @perforceResult) - 1){ 38. $perforceResult[$i] ~= s/<enter description>/Test Merge/g; 39. $perforceResult[$i] ~= s/<enter effort>/1/g; 40. } 41. open( PERFORCE "| p4 change -i" ); 42. print PERFORCE @perforceResult; 43. close PERFORCE; Let me know if you anything needs to change, as I am not into programming so I might doing somthing wrong. |
Quote:
#!/usr/bin/perl use strict; use warnings; #Get the workflow log my $logfile ="/home/ocd/msc/auto/integration/code/log.log"; open LOG, ">>$logfile" or die $!; print LOG "starting of the script \n"; my $list = "/home/ocd/msc/auto/integration/code/list.txt"; print LOG "$list"; open(DAT, $list) || die("Could not open file!"); foreach $line (<DAT>) { if($line){ print LOG "$line\n"; $my_string= $line;#chomp($line); my @values = split(' ', $my_string); $firstvalue=$values[0]; $secondvalue=$values[1]; $thirdvalue=$values[2]; print "$firstvalue\n"; print "$secondvalue\n"; print "$thirdvalue\n"; my $fifthCommand = "p4 -c iwork change -o $thirdvalue | sed -e "s/<enter description>/Test Merge/g/\;/s/<enter effort>/1/g" | p4 change -i"; my $secondCommand = "p4 -c iwork integrate -c $thirdvalue -o -f $firstvalue $secondvalue"; my $thirdCommand = "p4 -c iwork resolve -at"; my $fourthCommand = "p4 -c iwork submit -c $thirdvalue"; #print "1-$firstCommand \n"; print "2-$fifthCommand \n"; print "3-$secondCommand \n"; print "4-$thirdCommand \n"; print "5-$fourthCommand \n"; #my $error = "$? \n"; print LOG $dataResult; print LOG "error:$error"; if($error!=0) { print LOG "$error \n"; } }} ----- |
Code:
my $firstvalue=$values[0]; Code:
open( PERFORCE, "| p4 change -i" ); --- rod. |
Rod,
Yes the comma error has been resloved but still from your code I'm getting following error, Im postion errors and code at line# 37 & 38. I honestly apprecieate your help, since Iam 000 at coding. Thanks in advace. Eeorr syntax error at Integration.pl line 37, near "] ~" syntax error at Integration.pl line 38, near "] ~" Execution of Integration.pl aborted due to compilation errors. --- code at line 37 & 38 $perforceResult[$i] ~= s/<enter description>/Test Merge/g; $perforceResult[$i] ~= s/<enter effort>/1/g; if you want you can take a look at my compete code in this postings. |
Quote:
Cheers, Tink |
That'll be because the operator isn't ~=, but =~
after making changes to the syntax I am not getting any erorrs but the command failing because of input and output of command. Error after running script Unknown command. Try 'p4 help' for info. Error in change specification. Missing required field 'Change'. my original command to be run my $fifthCommand = "p4 -c change -o $thirdvalue | sed -e "s/<enter description>/Test Merge/g/\;/s/<enter effort>/1/g" | p4 change -i"; |
Quote:
Code:
warn "\$fifthCommand=$fifthCommand"; ... Don't you need to escape double quotes ? I.e. shouldn't your command actually be: Code:
my $fifthCommand = "p4 -c change -o $thirdvalue | sed -e \"s/<enter description>/Test Merge/g/\;/s/<enter effort>/1/g\" | p4 change -i"; |
Quote:
It looks like the argument to the 'p4' command is not 'change' but is 'Change'. --- rod. |
Quote:
my $firstCommand = "p4 change -o $thirdvalue | sed -e 's/<enter description>/Test Merge/g' | p4 change -i"; my $firstCommand1 = "p4 change -o $thirdvalue | sed -e 's/<enter effort>/1/g' | p4 change -i"; Thank you so much all the time you have spend to help me, I really appreciate. |
All times are GMT -5. The time now is 04:20 PM. |