lil_v has asked for the wisdom of the Perl Monks concerning the following question:

Since the system() operation inherits the standard input, output and error from the program. Is it possible to change the output folder to a desired path?

Replies are listed 'Best First'.
Re: system() - output folder?
by pc88mxer (Vicar) on Jul 18, 2008 at 16:37 UTC
    You can use shell I/O redirection:
    system("program < input-file > output-file");
      my code runs like this:
      my $executable = "C:/Desktop/file.exe"; my $output = "C:/Desktop/Folder"; system("$executable", "Argument") == 0 or die "system failed: $?";
      The program 'file.exe' generates output files on its own, I just need to specify the folder so it outputs it there.

        you can chdir to $output before you do your system call.

        if you save your current workdir (Cwd - getcwd) before that chdir, you can chdir back to the previous workdir afterwards, if necessary.

        update: minor text changes, so it is (hopefully) more precise