From: Gary Y. <gar...@ya...> - 2008-01-24 19:02:43
|
Hi All, I need to port my Perl script from Unix to Windows. Can someone tell me how to figure out which platform I am on? i.e. I need to know which Perl command can help me determin the platform. Once I know the platform, I'll code my script as the example bellow. But, how to figure out I am on Windows or Unix? if ($usingUNIX) { $directory = `ls`; #UNIX version. $copyCommand = `cp`; #UNIX version. } else { $directory = `dir`; #Win32 version. $copyCommand = `COPY`; #Win32 version. } Second question: The UNIX #!/usr/bin/perl notation does not work with Perl scripts on Windows. How should I code if it is Unix I place "#!/usr/bin/perl" at the very first line of the script? But, I do not place it at the first line of code if it is not Unix? How should I do it? Your answers are greatly appreciated. Thanks, Gary --------------------------------- Looking for last minute shopping deals? Find them fast with Yahoo! Search. |
From: Charles A. <cha...@al...> - 2008-01-24 19:53:08
|
http://perldoc.perl.org/perlvar.html#$OSNAME $^O or "use English" and $OSNAME will tell you a little more than what =20 you're trying to do. What you're trying kind of reminds me of how =20 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 =20 Windows. But, you can always run your Perl code from the command line =20 by explicitly calling perl. Example: "%> perl myscript.pl". That =20 works no matter the OS you're using. Under Windows, you can optionally associate files with .pl extensions =20 with the perl.exe executable. That shouldn't be too hard to figure =20 out in your windows explorer: just double click a .pl file. Windows =20 associations also work from the command line. Although, if you're =20 running your scripts as cgi scripts under apache on Windows, you can =20 do both the shebang line or windows file extension associations. Just =20 check out your apache configuration file.... Just to let you know, your question was posted to mailing list for the =20 Win32-GUI module, so it wasn't really topical for this mailing list. =20 If you have any other questions regarding running Perl under windows =20 or unix, they would be better addressed in a different mailing list. =20 Activestate hosts a bunch like perl-win32-users or perl-unix-users. =20 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 should =20 > I do it? > > Your answers are greatly appreciated. > > > Thanks, > > > Gary > > > > > --------------------------------- > Looking for last minute shopping deals? Find them fast with Yahoo! Search= . |
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. |
From: Reini U. <ru...@x-...> - 2008-01-24 19:54:42
|
Gary Yang schrieb: > Hi All, > > I need to port my Perl script from Unix to Windows. Can someone tell me > how to figure out which platform I am on? i.e. I need to know which Perl > command can help me determin the platform. Once I know the > platform, I'll code my script as the example bellow. But, how to figure > out I am on Windows or Unix? None of you questions are in any way related to this library. They should be asked at your local perl support group. $usingUNIX = ^O ne 'MSWin32'; > if ($usingUNIX) > { > $directory = `ls`; #UNIX version. > $copyCommand = `cp`; #UNIX version. > } > else > { > $directory = `dir`; #Win32 version. > $copyCommand = `COPY`; #Win32 version. > } Use the MakeMaker utils instead: perl -MExtUtils::Command -e mv source... destination perl -MExtUtils::Command -e cp source... destination `ls` is usually done via glob() or readdir() / use DirHandle. > Second question: > The UNIX #!/usr/bin/perl notation does not work with Perl scripts on > Windows. How should I code if it is Unix I place "#!/usr/bin/perl" at > the very first line of the script? But, I do not place it at the first > line of code if it is not Unix? How should I do it? The unix she-bang works ok on windows if your perl is in the path. #! perl is usually used, though the official way is to go through pl2bat for the windows version. > Your answers are greatly appreciated. > Thanks, > Gary -- Reini Urban http://phpwiki.org/ http://murbreak.at/ http://helsinki.at/ http://spacemovie.mur.at/ |