Re: redirecting output from a system command to a text file
by cdarke (Prior) on Apr 19, 2011 at 19:59 UTC
|
$a is a bad choice of variable names (as would $b), since it is a magic variable used in custom sorts, however I very much doubt if that is an issue here.
The rediection should work, and the creation of the file shows that the shell (probably cmd.exe) is creating the output file. A few things spring to mind that can create issues with cmd.exe:
Does the command-line (including $a) contain any quotes (other than the outer " used for Perl interpolation)?
Does the parameter in $a contain any imbedded whitespace?
You might like to replace the ./TVT.exe with echo to eliminate these issues. If that gets redirected correctly then you might need to look at the program. For example, is it writing to STDERR?
Update: I have done some experimenting, and cmd.exe does not seem particularly happy with the ./ prefix to the exe. I know you say it worked previously, but try removing it (it is not needed in Windows because the current directory is searched, whether it is in the %path% or not). | [reply] [d/l] [select] |
|
|
Actually, I got it to work by putting ticks around the $a:
system("./TVT.exe '$a' >test.txt");
I am not quite sure why that worked, but it does.
| [reply] [d/l] |
|
|
I just noticed that you are running under Cygwin in one of your replies, so the stuff about the current directory and %path% does not apply.
There must be a char in the filename that the shell finds interesting.
| [reply] |
|
|
|
|
In this instance the entire name is:
Test/W001#00100/TestReport_W001#00100_110327_235516.pdf
When I removed the "./" it says it can't find the command.
| [reply] |
Re: redirecting output from a system command to a text file
by believer (Sexton) on Apr 19, 2011 at 18:25 UTC
|
It should not make a difference. Are you sure that there are no "bad" characters in $a? What is the output of
print "./TVT.exe $a >test.txt";
| [reply] [d/l] |
|
|
when I do
print"./TVT.exe $a >test.txt";
It prints exactly the path and the name of the file I want,
plus it has TVT.exe in front of it.
I agree, it shouldn't make any difference.
| [reply] [d/l] |
|
|
But what is the name of the file? I'm guessing that your shell doesn't like "#", maybe treating it as the start of a comment.
| [reply] |
|
|
Re: redirecting output from a system command to a text file
by mellon85 (Monk) on Apr 19, 2011 at 18:21 UTC
|
You are on Win and using bash redirection?
I'm not familiar at all with the Win environment. As a stupid workaround I would just do
open my $input "./TVT.exe Tes...._235516.pdf|";
open my $output "test.txt"
foreach (<$output>) {
print $output,$_;
}
| [reply] [d/l] |
|
|
Hmm, the problem with that is i need to use the $a variable like this:
open my $input "./TVT.exe $a|";
"string found where operator expected" there. I am runniing this on an xp machine using a cygwin console.
| [reply] [d/l] |
|
|
open my $input,"TVT.exe Tes...._235516.pdf|" or die "$!";
there might be an issue with ./ | [reply] [d/l] |
Re: redirecting output from a system command to a text file
by mark4444az (Sexton) on Apr 19, 2011 at 22:03 UTC
|
OK, I got it. I had a newline at the end of my $a. I used chomp to get rid of it. Works great now. Thanks for all the feedback. | [reply] |