in reply to Replacing backticks with system() and redirecting STDERR to file

That's a little confusing to read, but it looks like you can exploit the 4-arg usage of open(): FILEHANDLE,MODE,EXPR,LIST. The reason it'll help is that you don't need to escape anything. I'm not 100% on that, but I'm pretty sure open will do a popen() directly when you use this format (rather than forking to a shell first). The docs do state that it may not work like I expect on all platforms.

open $sshNodeStdinHandle{$node}, "|-", "ssh", $node, qq(perl -e ...... +..) or die "couldn't open pipe: $!";

I'm pretty sure open doesn't return a pid, so I hope that isn't a problem. Otherwise you might need to look at IPC::Open3 or the like. UPDATE: It really does return a pid, but it's the pid of the shell for the two arg open and the pid of the process for the 4 arg version. Strange. I don't think that's documented, so I wouldn't count on it, but that's interesting anyway.

-Paul

  • Comment on Re: Replacing backticks with system() and redirecting STDERR to file
  • Download Code