Problem getting command output
am 29.10.2007 20:06:43 von kingskippus
I'm running ActiveState Perl version v5.6.1 built for MSWin32-x86-
multi-thread.
I have a script that is being run from another application (HP
Openview Operations for Windows) under the NT Authority\SYSTEM
account, and when I try to collect the output of a command using
something like this:
my $output = `defrag -a c:`;
It comes back blank. It doesn't matter which command I try to run, it
always comes back blank. I really need the output of the command. If
I redirect it to a file like so:
`defrag -a c: > c:\\test.txt`;
It puts the correct info into the file.
I'm not sure why the output is being suppressed. I checked that STDIN
and STDOUT exists using the if (-t STDIN && -t STDOUT), and they both
seem to be.
Does anyone know if there's something special I need to do when trying
to read the output of system commands when scripts are run from within
an automated service-type application? I'm trying to avoid echoing
the results to a file and reading the file in if possible.
Thanks!
Re: Problem getting command output
am 29.10.2007 20:50:09 von krahnj
TonyV wrote:
>
> I'm running ActiveState Perl version v5.6.1 built for MSWin32-x86-
> multi-thread.
>
> I have a script that is being run from another application (HP
> Openview Operations for Windows) under the NT Authority\SYSTEM
> account, and when I try to collect the output of a command using
> something like this:
>
> my $output = `defrag -a c:`;
>
> It comes back blank. It doesn't matter which command I try to run, it
> always comes back blank. I really need the output of the command. If
> I redirect it to a file like so:
>
> `defrag -a c: > c:\\test.txt`;
>
> It puts the correct info into the file.
>
> I'm not sure why the output is being suppressed. I checked that STDIN
> and STDOUT exists using the if (-t STDIN && -t STDOUT), and they both
> seem to be.
>
> Does anyone know if there's something special I need to do when trying
> to read the output of system commands when scripts are run from within
> an automated service-type application? I'm trying to avoid echoing
> the results to a file and reading the file in if possible.
Try running it like this:
open PIPE, "defrag -a c: |" or die "Cannot open pipe from defrag: $^E":
my $output = do { local $/; };
close PIPE or warn $! ? "Error closing defag pipe: $!"
: "Exit status $? from defrag";
Then you may get some indication that there may be something wrong.
(Disclamer: I don't do Windows. YMMV)
John
--
use Perl;
program
fulfillment