XP is just a number | |
PerlMonks |
Re: Syntax details with "system"by thewebsi (Scribe) |
on Jul 20, 2012 at 05:49 UTC ( [id://982751]=note: print w/replies, xml ) | Need Help?? |
Yes, the two forms are different. In the first form, a system call (eg, the C function as implemented internally by the operating system for executing commands) is made with the arguments provided. In the second form, the string is passed to the shell to deal with. The difficulty that you are running into is with escaping of meta-characters (characters special to the shell, but not special to the internal system call). The first form (system call) is equivalent to automatically escaping all arguments. So when you say above that the first form "works", it really doesn't, as it just passes ">$output_file" as an argument to the command, which in general won't do what you want. I don't know of any way to do something like piping to a file using the first form (you normally use open() for that instead). The second form (shell command) probably doesn't work for you because you are not escaping characters that you want escaped. Escaping can be done automatically in Perl using quotemeta() or \Q...\E. As an example, consider: >echo two > oneIf you want this to echo "two > one", then you need to escape the ">": system "echo", "two", ">", "one";system "echo two \\> one"; system "echo " . quotemeta ( "two > one" ); system "echo \Qtwo > one\E"; If you want "two" to be piped to a file called "one", then you don't: system "echo two > one";
Arnon Weinberg Back2Front - The Web Site People
In Section
Seekers of Perl Wisdom
|
|