in reply to Re: redirecting output in perl
in thread redirecting output in perl

Thank you so much for your reply. I am using WinXP.

In fact, the command:
 system('echo hello'); works fine...

But, redirecting a command output to the file does not work.

Also, is there an easier way I can create a file other than:
unless ( -e $file ) { open ( FH, " > $file" ); close (FH); }


Thank you,
Lily

Replies are listed 'Best First'.
Re^3: redirecting output in perl
by sgifford (Prior) on Sep 20, 2004 at 21:21 UTC

    Perl only uses a shell to execute commands if the command string contains shell metacharacters, like the greater-than symbol used to redirect output. That's why it works with no redirection, but breaks with it.

    The solution, as others have said, is probably to add something to your path that has cmd.exe. Generally a Windows system will have this by default, so you may want to look into why your PATH doesn't have this.

    A quick hack that might help is something like:

    $ENV{PATH} .= ";c:\\windows\\command". ";c:\\windows\\system32". ";c:\\winnt\\system32";
Re^3: redirecting output in perl
by ikegami (Patriarch) on Sep 20, 2004 at 19:00 UTC

    Odd, both
    system("echo hello > tmp.log");
    and
    system("echo hello");
    work for me, as they should.

    As for creating a file, opening it for write-append does the trick:
    { local *FH; open(FH, '>>', $file) or die("...: $!\n"); }