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.
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.
what is in $testdir, and how was it set?
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;