I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2010-09-10 03:38:08.446547-07 by maxd
binary generated out of recursive perl script not working
Hi, I have a perl script which runs a new instance of the same script by the "system" command. Under Linux, I have generated an executable out of this script by the pp command (pp -o myScript myScript). When I run the executable, it works fine till the point where a new istance of the script is started, where I get the following error: "par.pl: Can't open perl script "-r": No such file or directory". Notice that "-r" is the first parameter that I pass to the new instance of the script. If I try to start the script with no parameters, it works (but clearly my script complains for missing parameters). Googling a little bit, I have found at http://hi.baidu.com/_xyw/blog/item/ea6d27501983c213377abe7a.html that they seem to have the same problem under Cygwin (quoting the relevant part in the following): "The generated executable only need cygwin1.dll to work. But if the executable need input arguments, it will show error message like par.pl: Can't open perl script *agr1*: No such file or directory. we then need to comment out the following two lines in .cpan\build\PAR-Packer-1.002-74Drb9\blib\script\par.pl: #die qq(par.pl: Can't open perl script "$progname": No such file or directory\n) # unless -e $progname; (near the line "package main;" in the par.pl) and redo the make." This fix does not work for me (it just avoids the error message). Any suggestion to fix this issue is greatly appreciated! Thanks a lot!
Direct Responses: 12938 | Write a response
Posted on 2010-09-10 10:27:23.325189-07 by roderich in response to 12932
Re: binary generated out of recursive perl script not working
How to you invoke the "recursive" script: system($0, ...) or what?
Direct Responses: 12939 | Write a response
Posted on 2010-09-11 02:39:01.61031-07 by maxd in response to 12938
Re: binary generated out of recursive perl script not working
In the following way: system "myScript ${command_line_option}"; where ${command_line_option} holds all the parameters that I need to pass to the script. Thanks for your help!
Direct Responses: 12940 | Write a response
Posted on 2010-09-11 05:43:33.904806-07 by roderich in response to 12939
Re: binary generated out of recursive perl script not working
That explains it.
Look into the cache directory where stuff packed into your executable is extracted to (it's usually called /tmp/par-USER/SHA1CHECKSUM). You should see a file called myScript there (i.e. with the same name as your packed executable), but it is NOT a copy of your executable. It is a special purpose perl interpreter (and always the same).
Now the packed executable runs in an environment where PATH has been augmented with the cache directory. Hence when you simply invoke myScript (i.e. without a path), you likely will run the file myScript in the cache directory. The error message you saw would support this theory.
Try to use system("$0 ...") instead. That should run the original executable (or script in the unpacked case). This has the addidtional benefit that you don't have to edit your script if you ever decide to rename myScript to something else :)
Cheers, Roderich
Direct Responses: 12941 | Write a response
Posted on 2010-09-13 06:27:36.185622-07 by maxd in response to 12940
Re: binary generated out of recursive perl script not working
Thanks a lot, Roderich!
Using system("$0 ...") solved my issue!
Cheers,
Massimiliano
Direct Responses: Write a response