From: Charles A. <cha...@al...> - 2008-01-24 20:03:31
|
Ugh. Once again, I write up another response without completely reading =20 what you're trying to do. Instead of determining the OS and then using backticks to execute =20 shell/OS specific commands, why don't you use OS independent libraries =20 to manipulate files and directories? Check out File::Copy or the Perl =20 builtins opendir and readdir (use DirHandle for a more OOP way to do =20 it). Or you could use "ExtUtils::Command" and keep only the unix =20 style commands. Thanks, Charles Alderman Quoting Charles Alderman <cha...@al...>: > http://perldoc.perl.org/perlvar.html#$OSNAME > > $^O or "use English" and $OSNAME will tell you a little more than what > you're trying to do. What you're trying kind of reminds me of how > Javascript'ers figure out the browser or XHR call they need. > > As far as the shebang line (#!...), you're right, that doesn't work in > Windows. But, you can always run your Perl code from the command line > by explicitly calling perl. Example: "%> perl myscript.pl". That > works no matter the OS you're using. > > Under Windows, you can optionally associate files with .pl extensions > with the perl.exe executable. That shouldn't be too hard to figure out > in your windows explorer: just double click a .pl file. Windows > associations also work from the command line. Although, if you're > running your scripts as cgi scripts under apache on Windows, you can do > both the shebang line or windows file extension associations. Just > check out your apache configuration file.... > > Just to let you know, your question was posted to mailing list for the > Win32-GUI module, so it wasn't really topical for this mailing list. > If you have any other questions regarding running Perl under windows or > unix, they would be better addressed in a different mailing list. > Activestate hosts a bunch like perl-win32-users or perl-unix-users. > See: http://aspn.activestate.com/ASPN/Perl/Mail/ > > Thanks, > Charles Alderman > > Quoting Gary Yang <gar...@ya...>: > >> Hi All, >> >> I need to port my Perl script from Unix to Windows. Can someone =20 >> tell me how to figure out which platform I am on? i.e. I need to =20 >> know which Perl command can help me determin the platform. Once I =20 >> know the platform, I'll code my script as the example bellow. But, =20 >> how to figure out I am on Windows or Unix? >> >> if ($usingUNIX) >> { >> $directory =3D `ls`; #UNIX version. >> $copyCommand =3D `cp`; #UNIX version. >> } >> else >> { >> $directory =3D `dir`; #Win32 version. >> $copyCommand =3D `COPY`; #Win32 version. >> } >> >> >> Second question: >> The UNIX #!/usr/bin/perl notation does not work with Perl scripts =20 >> on Windows. How should I code if it is Unix I place =20 >> "#!/usr/bin/perl" at the very first line of the script? But, I do =20 >> not place it at the first line of code if it is not Unix? How =20 >> should I do it? >> >> Your answers are greatly appreciated. >> >> >> Thanks, >> >> >> Gary >> >> >> >> >> --------------------------------- >> Looking for last minute shopping deals? Find them fast with Yahoo! Searc= h. |