Can I use Proc::Reliable on windows? - windows

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

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.
$

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/"

I have contacted the author of the Proc::Reliable module and he confirmed that the module does not work on Windows.

Related

Access Perl environment (shell) variables in Windows - $ENV not working

The issue
I found out how to use windows environment variables (e.g., %AppData%, %HomePath%, %SystemRoot%, etc.) in this SO post:
Getting the path of %AppData% in perl script
Here is the code snippet that was chosen as a working, correct answer:
#!/usr/bin/perl
use warnings;
use strict;
my $localConfPath = $ENV{localappdata};
my $appdata = $ENV{appdata};
print $localConfPath; #will print the app path - C:\users\xxx\AppData\local
print $appdata; #prints - C:\users\xxx\AppData\Roaming
However, this is not working on my machine in my code for some reason. My scripts work without the shebang (#!) line so I tried the script both with and without it, to no avail.
My set-up
I'm using the Perl that comes with GitBash, if that makes a difference.
What I've tried
I tried a simple Perl command line execution:
perl -e 'print %ENV{AppData}';
This didn't work. I also tried the following alternatives:
perl -e 'print %ENV{APPDATA}';
perl -e 'print %ENV{appdata}';
That also didn't work. Here's the error I get (the same for all 3 versions):
syntax error at -e line 1, near "%ENV{AppData"
Execution of -e aborted due to compilation errors.
I even tried to use the code from the SO post I mentioned in it's own file. That code doesn't work either. With the code from the post I get this error:
$ perl /c/Users/User1/Desktop/ehCode_testingWindowsEnvironmentVariables_01.pl
Use of uninitialized value in print at /c/Users/User1/Desktop/ehCode_testingWindowsEnvironmentVariables_01.pl line 7.
Use of uninitialized value in print at /c/Users/User1/Desktop/ehCode_testingWindowsEnvironmentVariables_01.pl line 8.
The lines in question then are these:
print $localConfPath; #will print the app path - C:\users\xxx\AppData\local
print $appdata; #prints - C:\users\xxx\AppData\Roaming
I don't see why they shouldn't work.
I've checked Perl Monks, Perl Maven, Stack Overflow, and other popular Perl resources, to no avail. Even Active State did not have the answer.
When you access individual items of a hash, you need to use the scalar sigil, $ as opposed to the hash sigil, %:
perl -e 'print $ENV{APPDATA}'

Undefined subroutine &UUID::generate called at

I am encountering a problem with the following perl script that someone else wrote to generate a uuid and print it to stdout. It likely has to do with a misconfigured perl setup on my Windows 7 machine with ActiveState's Perl from http://downloads.activestate.com/ActivePerl/releases/5.20.2.2001/ActivePerl-5.20.2.2001-MSWin32-x86-64int-298913.msi. I also have the Data::UUID perl module versiion 1.220 installed.
#!/usr/bin/perl
use UUID;
UUID::generate($uuid);
UUID::unparse($uuid, $string);
print $string . "\n"
When the script in a DOS shell is run with no arguments I get the following error:
Undefined subroutine &UUID::generate called at xxx
Any advice on how to debug this?

Run external command from within Perl

I am using Doxygen to generate HTML documentation and then run a Perl script to get function names.
To run Doxygen configuration, I need to run doxygen file_name in cmd.
But I want to run everything from Perl.
I tried this code
my $cmd = "perl -w otherscript.pl";
my $result = system("start $cmd");
But it just opens a cmd window. I need to execute cmd code directly through Perl (not a Perl command line, but through a Perl IDE). Is there a way to achieve this?
Your usage of system and start is OK.
From your description in the comment, I think it's because you're not using the correct escaping method when giving configure files to Doxygen that it throws such an error:
Error: configuration file C:SERSGHOSHBCD not found!
Try with
my $result = `doxygen C:\\Users\\aghosh\\abcd`;
In the two back-slashes, the former one is to escape the latter one, so that it's recognized by Windows as the directory separator.

Perl: Get minimum supported operating system for a binary

Is there a Perl command that lets me get the minimum supported OS for any given binary?
You can manually get that information by running "link /dump /headers [binaryFile]" and looking for the "subsystem version" link. I don't want to use that since it's got really bad perf.
Thanks
If you need this for Windows, use get_manifest from Win32::Exe. You will need to install it first.
If there's a command that gets what you want, why not just run that command?
You can use backticks or qx// in Perl to get a command's output
eg:
my $output = `command arg1 arg2 ...`;
Or, if you want an array of lines:
my #lines = `command arg1 arg2 ...`;
Then you can use Perl's normal facilities for scanning that output for patterns you're interested in.
Also, your command looks like it is for Windows - is that true? If so, you should add a Windows tag.

executing shell command from ruby

This isn't working in ruby and I don't understand why?
#!/usr/bin/env ruby
exec "sort data.txt > data.sort"
data.txt is a comma sepparated file. Anyway.. If I try to execute that line in the shell it works without a problem.
When I try to run this script from my script, I get an empty file.
This isn't really an answer, but I wanted to share that your original usage of exec is actually working for me. This was how I set it up.
data.txt
"1,2,3,4,5,6,7,8"
sort.rb (I don't know what your sort did so I am just writing the same data out)
File.open(ARGV[0]){|f| puts f.read}
irb session
irb(main):001:0> exec "sort data.txt > data.sort"
When I ran this in irb, I did get a data.sort output file and it contained "1,2,3,4,5,6,7,8" as expected. I can run the same exec line through irb or from another ruby file, and I get the output file with data each time.
I am running Ruby 1.8.6 on a 32bit Windows XP system.
Have you tried
%x(sort data.txt > data.sort)

Resources