Problem getting command output

T

TonyV

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!
 
J

John W. Krahn

TonyV said:
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 $/; <PIPE> };

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top