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 = <MAKEFILES>;
> 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

Reply via email to