Link to home
Start Free TrialLog in
Avatar of loveslave
loveslave

asked on

Redirect output to file in subdirectory

I have a problem with a perl script that should redirect output to a certain file in a certain directory. The problematic line is
system "echo teststring >$testdir\\log.txt";

This is running on Windows 2000.

Changing the line to just
system "echo teststring >log.txt";
works fine, but when a subdirectory is specified, the file is never created and I don't get any output at all.

Avatar of ozo
ozo
Flag of United States of America image

what is in $testdir, and how was it set?
Avatar of loveslave
loveslave

ASKER

Sorry, I should have said that from the beginning.
The value of $testdir doesn't seem to matter. Even if I do

system "echo teststring >Test\\log.txt";

I get the same error (no output, no file is created). In this case, Test is an existing subdirectory of the directory from where I call the perl script.

If I make the same call at a command prompt (echo teststring >Test\\log.txt) I get the desired result.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why not just do it in Perl, eg:


open LOG, ">Test/log.txt" or die "Can not write to Test/log.txt $!\n";
print LOG "teststring\n";
close LOG;

Open in new window