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.
Related
I'm using Ruby on Linux.
I'd like to test for the existence of a command on the Linux system.
I'd like to not get back the output of the command that I'm testing for.
I'd also like to not get back any output that results from the shell being unable to find the command.
I want to avoid using shell redirection from within the command that I send to the shell. So something like system("foo > /dev/null") would be unsuitable.
I'm ok with using redirection if there is a way to do it from Ruby.
The simplest thing would be just to use system. Let's say you're looking for ls.
irb(main):005:0> system("which ls")
/bin/ls
=> true
If that's off the table, you could peek into the directories in ENV["PATH"] for the executable you're looking for. ENV["PATH"].split(":") would give you an array of directory names to check for the desired command. If you find a file with the right name, you may want to ensure it's an executable.
I want to avoid using shell redirection from within the command that I
send to the shell. So something like system("foo > /dev/null") would
be unsuitable. I'm ok with using redirection if there is a way to do it from Ruby.
system("exec which cmd", out: "/dev/null")
puts "Command is available." if ($?).success?
The exec is to explicitly avoid unnecessary forking in the shell.
As a sidenote type -P can be used instead of which, but it relies on Bash and may have surprising effects if script is ported to an environment with a different default shell.
If you are in a Cygwin or MinGW bash shell, environment variables like $PATH are in "UNIX" format - using forward slashes as dir separators and using the colon to separate multiple paths. But if, inside this shell, you run something like cmd.exe /c 'echo %PATH%' the resulting output is in "Windows" format, using backslashes and semicolons respectively.
Is this magical conversion documented somewhere? Or better yet, can somebody point to the code that makes this happen?
(The reason I ask is because it seems the conversion doesn't always happen and I'm trying to understand the exact conditions needed for it to occur.)
The internal conversions between Unix and Windows path format are
performed by the funtions in path.cc
https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/path.cc;h=3cb46c9c812e17460d56def2f915b21c7227f3bf;hb=HEAD
When a Cygwin program executes a Windows program the spawn process is
performed by functions in spawn.cc
https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/spawn.cc;h=37db52608e24e866e80401668ef13562f0cb67ea;hb=HEAD
If you need more details or ask clarification use the cygwin mailing list.
I am new to Erlang and I am trying to find an easy way to output Erlang command results to a test file in Windows command line. This is what I tried so far:
c:\Windows\Temp>erl example.erl "main" -e > output.txt
if its a small script perhaps you can use escript as described in here
escript provides support for running short Erlang programs without
having to compile them first and an easy way to retrieve the command
line arguments
then you can get what you want to work the way you want
escript myfunctions_tests > output.txt
Is it possible to call winrar through perl on a windows system, such as
perl -e "rar a -rr10 -s c:\backups\backup.rar #backup.lst"
If so, is there a more efficient way to do this?
I've looked up "perl -e" +winrar on google, however none of the results gave me any answer that was remotely close to what i was looking for. The system Im running this on is a Windows XP system. Im open to doing this in another language like python if its easier, however I am more comfertable with perl.
You can access the RAR facilities in Windows using the CPAN module Archive::Rar:
use Archive::Rar;
my $rar = Archive::Rar->new(-archive => $archive_filename);
$rar->Extract();
One way to execute external commands from a Perl script is to use system:
my $cmd = 'rar a -rr10 -s c:\backups\backup.rar #backup.lst';
if (system $cmd) {
print "Error: $? for command $cmd"
}
To use external applications from your Perl program, use the system builtin.
If you need the output from the command, you can use the backtick (``) or qx operator as discussed in perlop. You can also use pipes as discussed in perlipc.
What is the best way to programatically determine if a Perl script is executing on a Windows based system (Win9x, WinXP, Vista, Win7, etc.)?
Fill in the blanks here:
my $running_under_windows = ... ? 1 : 0;
From perldoc perlvar:
$OSNAME
$^O
The name of the operating system under which this copy of Perl was built, as determined during the configuration process. The value is identical to $Config{'osname'}. See also Config and the -V command-line switch documented in perlrun.
In Windows platforms, $^O is not very helpful: since it is always MSWin32, it doesn't tell the difference between 95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or Win32::GetOSVersion() (see Win32 and perlport) to distinguish between the variants.
$^O eq 'MSWin32'
(Source: The perlvar manpage)
Use Devel::CheckOS. It handles all of the logic and special cases for you. I usually do something like:
use Devel::CheckOS qw(die_unsupported os_is);
die "You need Windows to run this program!" unless os_is('MicrosoftWindows');
The 'MicrosoftWindows' families knows about things such as Cygwin, so if you are on Windows but not at the cmd prompt, os_is() will still give you the right answer.
This is very quick and dirty, and wouldn't bet it's 100% portable, but still useful in a pinch.
Check for presence of back slashes in the PATH Env variable, since PATH is common to both Windows and Unix.
So - in Perl:
if ( $ENV{PATH}=~m{\\} ) {
#Quick and dirty: It's windows!
print "It's Windows!";
} else {
print "It's Unix!";
}