in reply to Trying to get an external c program to print to a file

You can't redirect STDOUT of an external program with system without using the shell. So you should be using a command line as the single argument to system. Multiple arguments just won't work in this case.
  • Comment on Re: Trying to get an external c program to print to a file

Replies are listed 'Best First'.
Re^2: Trying to get an external c program to print to a file
by akrrs7 (Acolyte) on Nov 04, 2011 at 12:06 UTC
    Hello Bart, I did not follow your suggestion. Thanks...
      I mean that
      system("$PGMEXEC1", "-arg1=$arg1", "-arg2=$arg2", ">${workingDir}${ps +}$outputFile1");
      will not work, you have to use something like
      system("$PGMEXEC1 -arg1=$arg1 -arg2=$arg2 >${workingDir}${ps}$outputFi +le1");
      See system for the difference between the two.

      If your variable arguments can contain spaces or other characters that are special for the shell, you'll have to escape them. If on Linux or another Unix-derivative, you can use the module String::ShellQuote to handle the hard work. If on Windows, just putting double quotes around the arguments should do, unless you're making life really hard on yourself. (You can wrap the whole command line in qq so you don't have to escape the quotes. Oh, you can't use single quotes there because the variables need to be replaced by their values.)

        But you can write:
        system "'$PGMEXEC1' '-arg1=$arg1' '-arg2=$arg2' > '${workingDir}${ps}$ +outputFile1'";
        Which works fine, unless any of the variables contains a single quote, or ends in a backslash.