Re: how to get the output from: Win32::Process::Create



joez3@xxxxxxxxx wrote:
Paul Lalli wrote:
joez3@xxxxxxxxx wrote:
Hi all,
This might be more a windows question then perl, but lets see if
someone can help me out. I am using Win32::Process::Create to start up
an exe. I can get exe to start, but I need to get what is put out on
the command prompt.
If i try text.exe > temp.txt I can start the exe and the temp.txt file
gets created, but nothing is in it. The text is put in another command
prompt window. So this rules out using system () to start the exe.

Is there any particular reason you're not just using backticks?

perldoc perlop
(search for qx)

I am not sure what the backticks buy me,

They buy you the ability to get the output of your program, which is
what you said you wanted.

i can start up the exe with
the Process::Create. Maybe i should have said more about the exe under
test, its a program that will stay up untill I kill it. By using the
Process::Create I can get the pid and use that to kill it. With the
backticks I tried the following:
open (FHCMD, `start test.exe`." | ");

This makes just as little sense as your original.
Win32::Process::Create returns either 0 or non-zero depending on
whether or not the program was successfully started. Backticks return
the output of the command. You're trying to open a pipe to these
return values, instead of opening a pipe to the actual command.

while (<FHCMD>) {
print $_;
}
This starts the test.exe, but it ends up hanging the perl script and I
can't get the contents of FHCMD.
What should I try next?

You should take a step back and think about what it is you're actually
trying to do, and how to go about doing it. Your last two attempts
have been nonsensical, which is a sure sign that you've reached the
point of frustration and are now throwing things at the wall to see
what sticks.

You apparently have two requirements. One is that you need to capture
the output of the program. The other is that you need to get the pid
of the program so you can later kill it. These two requirements seem,
to me, to be contraditory. The only way it makes sense is if you don't
want your Perl script to do anything else while this program is
running. Is that correct? If so: open a pipe to the process. Start
reading its output. Whenever you've decided you want to kill it, exit
the loop and close the handle. IIRC, that will send a SIGPIPE to the
program, effectively terminating it.

open my $pipe, "test.exe |" or die "Cannot start program: $!";
while (my $line = <$pipe>) {
#do something with $line
if (want_to_kill()) {
last;
}
}
close $pipe;

Paul Lalli

.



Relevant Pages

  • Re: UTF-8 without external modules on Perl 5.0
    ... algorithms/whatever right before worrying about the character encoding. ... you think about the tools which turn a Perl source in an exe? ... they embedd a 5.8 Perl interpreter? ... Do you think I could write this 5.8 version and just convert to exe ...
    (comp.lang.perl.misc)
  • Re: Mail::Sender problem
    ... I converted this to exe format. ... in your host machine" ... Can you successfully convert and run Perl exe programs that do not use ...
    (comp.lang.perl.modules)
  • Re: help a beginner decide
    ... I like the idea of being able to compile an single EXE to run ... other files (.dll libraries for example) being installed, ... Perl, the ActiveState Perl Development Kit is a good choice. ... Not sure what the equivalent for Java ...
    (comp.programming)
  • PAR/PP on Windows XP with ActiveState
    ... I am trying to build an EXE without the Perl DLL included. ... Reduce the executable size by not including a copy of perl interpreter. ... Executables built this way will need a separate perl5x.dll or ... is built as a shared library. ...
    (comp.lang.perl.misc)
  • Re: Perl Query - Conversion of EXE file
    ... On 12/5/06, Jenda Krynicky wrote: ... Suppose the file does not contain any thing perl ... a EXE for the Perl Program is created in Windows. ... the input file is some text file containing some raw data. ...
    (perl.beginners)