views:

40

answers:

2

I'm using ActivePerl on a Win 7 box and I want to use the Proc::Reliable CPAN module. It downloaded and installed properly but when I tried to run the following code, it failed at run

my $newProc = Proc::Reliable->new()
$newProc->run("perl.exe -e print 'hello world'");

I tried a couple things, such as testing the status and trying to retrieve output, but with no luck. As best as I can tell, the program dies silently on run.

For reference perl.exe is in my PATH variable and I'm calling this from commandline as: perl.exe test.pl

+4  A: 

It probably isn't failing. -e print 'hello world' tells perl to execute the code print with @ARGV set to hello world (or perhaps ("'hello","world'"), I forgot how windows cmd quoting handles ''). This prints the contents of $_ (that is, undef) to STDOUT.

Always use warnings. Even on one-liners. Perhaps especially on one-liners. Compare:

$ perl -e print 'hello world'
$

and

$ perl -we print 'hello world'
Use of uninitialized value $_ in print at -e line 1.
$
ysth
If I believed my program was failing for other reasons, what would be the correct way to test it? I used -e print, because it was quick, is there any other way?
tzenes
@tzenes: sorry, I don't actually know anything about Proc::Reliable. It seems like it should provide some well documented way to test, though. Change the inner program to create a file or output a debugging statement to see if it's starting at all?
ysth
+3  A: 

Quoting is a little different in the Windows "shell". To get your mini-program to be interpreted as a single argument, try something like

perl.exe -e "print qq/hello world/"
mobrule
While that does work for windows "shell" it won't display any output in my example as the stdout isn't redirect to the "shell" (or anywhere else).
tzenes
@tzenes: What if you say `($stdout) = $newProc->run('perl.exe -e ...'); print $stdout` ? It looks like the output of the process should be captured by the `Proc::Reliable` module and returned.
mobrule
@Mobrule I get no output or the print $stdout fails. Upon further investigation, any `print` after a `run` fails.
tzenes