in reply to Re^2: CLASSPATH problem when using backticks
in thread CLASSPATH problem when using backticks

Is this available in a standard module? If not, I think it should be. The situation seems to comes up enough. I'd like to deprecate all calls to exec which invoke an intermediate shell and replace them with safer alternatives.

Update: Banning all use of the single-argument forms of exec, system, etc. is probably too draconian. The real problem occurs when a variable is interpolated in that single argument, e.g. my $output = `command $arg`. Perhaps this is something that Perl::Critic can look for and advise that a safer way should be sought to perform the operation.

Replies are listed 'Best First'.
Re^4: CLASSPATH problem when using backticks
by ikegami (Patriarch) on May 22, 2008 at 07:08 UTC

    Banning all use of the single-argument forms of exec, system, etc. is probably too draconian.

    Not really. It would just force the shell to be mentioned explicitly when it's needed. For example,

    system('sh', '-c', 'some_program >output 2>&1');

    That would hurt portability to Windows, but launching processes in Windows is so messed up already. And not just at the shell level, at the system level. All the arguments you carefully separated are assembled into a command line, cause that's the only way the system can pass args to a program.