Re: use system() function
Hi. Maybe if u gave a more high level description of what ur trying to do we might be able to help u more. I think what ur going for is a find/replace on a list of files? If so, this is not the way to do it. A generic find/replace would be like: foreach $file (@files) { open FILE, "<", $file; my $text = join "", ; close FILE; $text =~ s/aaa/bbb/g; open OUT, ">", $file; print OUT $text; close OUT; } But beware, that kind of simplistic find/replace is not very robust. At 09:14 AM 5/13/2009 +0900, Chang Min Jeon wrote: >hello > >I trying to modify file using perl one line like below. > >my $cmd = "perl -pi -e's/aaa/bbb/' "; > >open(MAKEFILES, '<', $ARGV[0]) or die "file open error"; >my @filelist = ; >foreach my $file (@filelist) { >chomp($file); >my $command = $cmd.$file; >print $command,"\n"; >!system($command) or die "shell command not work"; >} >close(MAKEFILES); > >but system function does not work. > -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: use system() function
Hi. Chang Min Jeon wrote: > > I trying to modify file using perl one line like below. > > my $cmd = "perl -pi -e's/aaa/bbb/' "; I think that there should be a space between the -e and the regular expression my $cmd = "perl -pi -e 's/aaa/bbb/' "; If you're in the Windows world, you might also want to try using double quotes around the regular expression my $cmd = 'perl -pi -e "s/aaa/bbb/" '; > > open(MAKEFILES, '<', $ARGV[0]) or die "file open error"; > my @filelist = ; > foreach my $file (@filelist) { > chomp($file); > my $command = $cmd.$file; > print $command,"\n"; > !system($command) or die "shell command not work"; > } > close(MAKEFILES); > > but system function does not work. > > It print > > ./Windowset/Common/Makefile.gmk > perl -pi -e's/-+g -+dwarf2//' ./Windowset/Common/Makefile.gmk > : No such file or directory.mmon/Makefile.gmk > ./Windowset/Special/Makefile.gmk > perl -pi -e's/-+g -+dwarf2//' ./Windowset/Special/Makefile.gmk > : No such file or directory.cial/Makefile.gmk > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: use system() function
From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of mohammed.must...@wipro.com Sent: 13 May 2009 06:30 To: jcm1...@gmail.com; Perl-Win32-Users@listserv.ActiveState.com Subject: RE: use system() function > Hi Chang Min Jeon, > > Please use back stick operator here, instead of system command, because system command doesn't return > anything. Not so. From 'perldoc -f system': "The return value is the exit status of the program as returned by the "wait" call." HTH -- Brian Raven This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: use system() function
From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Chang Min Jeon Sent: 13 May 2009 01:14 To: Perl-Win32-Users@listserv.ActiveState.com Subject: use system() function > hello > > I trying to modify file using perl one line like below. > > my $cmd = "perl -pi -e's/aaa/bbb/' "; That might not work in Win32 platforms. The command shell doesn't know how to handle single quotes. You should use double quotes. Try something like: my $cmd = qq{perl -pi -e "s/aaa/bbb/g" }; > > open(MAKEFILES, '<', $ARGV[0]) or die "file open error"; > my @filelist = ; > foreach my $file (@filelist) { > chomp($file); > my $command = $cmd.$file; > print $command,"\n"; > !system($command) or die "shell command not work"; Personally I prefer something like: system $command; $? == 0 or die "Command '$command' failed with exit code $?\n"; A bit more verbose perhaps, but I think that the intent is clearer. > } > close(MAKEFILES); > > but system function does not work. > > It print > > ./Windowset/Common/Makefile.gmk > perl -pi -e's/-+g -+dwarf2//' ./Windowset/Common/Makefile.gmk > : No such file or directory.mmon/Makefile.gmk > ./Windowset/Special/Makefile.gmk > perl -pi -e's/-+g -+dwarf2//' ./Windowset/Special/Makefile.gmk > : No such file or directory.cial/Makefile.gmk It seems fairly clear that the above output was not produced by the code that you supplied. This only serves to confuse those who might be able to help. As it is, I can't reproduce the behaviour you describe. A small, self-contained example script, that we could simply cut&paste and run would be better, along with the output generated when you ran the same code. Also, what happens when you execute those commands manually? HTH -- Brian Raven This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: use system() function
Hi, I have not tried below code, but I suggest you few more things here, 1) my $cmd = "perl -pi -e 's/aaa/bbb/g' ";# you are are missing g here. I doubht below command is working. my $command = $cmd.$file; ## is concatenation operator required here. Bit busy now meanwhile try aboove code changes , I hope some good friends on this forum will solve query if I won't find time. I will check the code, if I find sometime. -- Regards, Mustafa From: Chang Min Jeon [mailto:jcm1...@gmail.com] Sent: Wednesday, May 13, 2009 2:05 PM To: Mohammed Mustafa (WT01 - PES-Semi-Technology) Cc: Perl-Win32-Users@listserv.activestate.com Subject: Re: use system() function Hi mustafa Thank you for your help. I changed following code but it still doesn't work. my $cmd = "perl -pi -e's/aaa/bbb/' "; open(MAKEFILES, '<', $ARGV[0]) or die "file open error"; my @filelist = ; foreach my $file (@filelist) { chomp($file); my $command = $cmd.$file; print $command,"\n"; my $result = `$command`; if($result) { print "success\n"; } else { print "failed\n"; } } close(MAKEFILES); ./Windowset/Common/Makefile. gmk perl -pi -e's/-+g -+dwarf2//' ./Windowset/Common/Makefile.gmk : No such file or directory.mmon/Makefile.gmk failed ./Windowset/Special/Makefile.gmk perl -pi -e's/-+g -+dwarf2//' ./Windowset/Special/Makefile.gmk : No such file or directory.cial/Makefile.gmk failed 2009/5/13 Hi Chang Min Jeon, Please use back stick operator here, instead of system command, because system command doesn't return anything. Replace the system command with, $Result = `$command`; If ($Result) { Print " appropriate message \n"; } else { print " Failed message \n"; } -- Regards, Mustafa From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Chang Min Jeon Sent: Wednesday, May 13, 2009 5:44 AM To: Perl-Win32-Users@listserv.ActiveState.com Subject: use system() function hello I trying to modify file using perl one line like below. my $cmd = "perl -pi -e's/aaa/bbb/' "; open(MAKEFILES, '<', $ARGV[0]) or die "file open error"; my @filelist = ; foreach my $file (@filelist) { chomp($file); my $command = $cmd.$file; print $command,"\n"; !system($command) or die "shell command not work"; } close(MAKEFILES); but system function does not work. It print ./Windowset/Common/Makefile.gmk perl -pi -e's/-+g -+dwarf2//' ./Windowset/Common/Makefile.gmk : No such file or directory.mmon/Makefile.gmk ./Windowset/Special/Makefile.gmk perl -pi -e's/-+g -+dwarf2//' ./Windowset/Special/Makefile.gmk : No such file or directory.cial/Makefile.gmk someone who meet this problem? Thanks in advance -- CashFlow To be rich. Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com -- CashFlow To be rich. Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: use system() function
Hi mustafa Thank you for your help. I changed following code but it still doesn't work. my $cmd = "perl -pi -e's/aaa/bbb/' "; open(MAKEFILES, '<', $ARGV[0]) or die "file open error"; my @filelist = ; foreach my $file (@filelist) { chomp($file); my $command = $cmd.$file; print $command,"\n"; my $result = `$command`; if($result) { print "success\n"; } else { print "failed\n"; } } close(MAKEFILES); ./Windowset/Common/Makefile.gmk perl -pi -e's/-+g -+dwarf2//' ./Windowset/Common/Makefile.gmk : No such file or directory.mmon/Makefile.gmk failed ./Windowset/Special/Makefile.gmk perl -pi -e's/-+g -+dwarf2//' ./Windowset/Special/Makefile.gmk : No such file or directory.cial/Makefile.gmk failed 2009/5/13 > Hi Chang Min Jeon, > > Please use back stick operator here, instead of system command, because > system command doesn't return anything. > > Replace the system command with, > > $Result = `$command`; > If ($Result) { > Print " appropriate message \n"; > } else { > print " Failed message \n"; > } > > -- > Regards, > Mustafa > > > -- > *From:* perl-win32-users-boun...@listserv.activestate.com [mailto: > perl-win32-users-boun...@listserv.activestate.com] *On Behalf Of *Chang > Min Jeon > *Sent:* Wednesday, May 13, 2009 5:44 AM > *To:* Perl-Win32-Users@listserv.ActiveState.com > *Subject:* use system() function > > hello > > I trying to modify file using perl one line like below. > > my $cmd = "perl -pi -e's/aaa/bbb/' "; > > open(MAKEFILES, '<', $ARGV[0]) or die "file open error"; > my @filelist = ; > foreach my $file (@filelist) { > chomp($file); > my $command = $cmd.$file; > print $command,"\n"; > !system($command) or die "shell command not work"; > } > close(MAKEFILES); > > but system function does not work. > > It print > > ./Windowset/Common/Makefile.gmk > perl -pi -e's/-+g -+dwarf2//' ./Windowset/Common/Makefile.gmk > : No such file or directory.mmon/Makefile.gmk > ./Windowset/Special/Makefile.gmk > perl -pi -e's/-+g -+dwarf2//' ./Windowset/Special/Makefile.gmk > : No such file or directory.cial/Makefile.gmk > > someone who meet this problem? > > Thanks in advance > -- > CashFlow > To be rich. > > * Please do not print this email unless it is absolutely necessary. * > > The information contained in this electronic message and any attachments to > this message are intended for the exclusive use of the addressee(s) and may > contain proprietary, confidential or privileged information. If you are not > the intended recipient, you should not disseminate, distribute or copy this > e-mail. Please notify the sender immediately and destroy all copies of this > message and any attachments. > > WARNING: Computer viruses can be transmitted via email. The recipient > should check this email and any attachments for the presence of viruses. The > company accepts no liability for any damage caused by any virus transmitted > by this email. > > www.wipro.com > -- CashFlow To be rich. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: use system() function
Hi Chang Min Jeon, Please use back stick operator here, instead of system command, because system command doesn't return anything. Replace the system command with, $Result = `$command`; If ($Result) { Print " appropriate message \n"; } else { print " Failed message \n"; } -- Regards, Mustafa From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Chang Min Jeon Sent: Wednesday, May 13, 2009 5:44 AM To: Perl-Win32-Users@listserv.ActiveState.com Subject: use system() function hello I trying to modify file using perl one line like below. my $cmd = "perl -pi -e's/aaa/bbb/' "; open(MAKEFILES, '<', $ARGV[0]) or die "file open error"; my @filelist = ; foreach my $file (@filelist) { chomp($file); my $command = $cmd.$file; print $command,"\n"; !system($command) or die "shell command not work"; } close(MAKEFILES); but system function does not work. It print ./Windowset/Common/Makefile.gmk perl -pi -e's/-+g -+dwarf2//' ./Windowset/Common/Makefile.gmk : No such file or directory.mmon/Makefile.gmk ./Windowset/Special/Makefile.gmk perl -pi -e's/-+g -+dwarf2//' ./Windowset/Special/Makefile.gmk : No such file or directory.cial/Makefile.gmk someone who meet this problem? Thanks in advance -- CashFlow To be rich. Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
use system() function
hello I trying to modify file using perl one line like below. my $cmd = "perl -pi -e's/aaa/bbb/' "; open(MAKEFILES, '<', $ARGV[0]) or die "file open error"; my @filelist = ; foreach my $file (@filelist) { chomp($file); my $command = $cmd.$file; print $command,"\n"; !system($command) or die "shell command not work"; } close(MAKEFILES); but system function does not work. It print ./Windowset/Common/Makefile.gmk perl -pi -e's/-+g -+dwarf2//' ./Windowset/Common/Makefile.gmk : No such file or directory.mmon/Makefile.gmk ./Windowset/Special/Makefile.gmk perl -pi -e's/-+g -+dwarf2//' ./Windowset/Special/Makefile.gmk : No such file or directory.cial/Makefile.gmk someone who meet this problem? Thanks in advance -- CashFlow To be rich. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs