Is there a way to pass command line arguments to a Perl program you are running from the Padre menu ("Run->Run Script")?
Under Tools->Preferences->"Language - Perl5", set "Script arguments" and save.
Or under Tools->Preferences->Advanced, see "run_script_args_default". Set a value, and save.
Either way they do the same thing. You can also use the "Interpreter Arguments" field to set flags for the Perl interpreter.
Related
I run the Lua script using command line:
scipt.lua arg
But when I want to print the value arg1 in script:
print(arg[1])
Result is nil.
When I try to run it like:
lua script.lua arg
It returns not recognized command for windows.
What I am doing wrong? How can I get parameters from command line?
I don't see any problem with your example. Since you are able to run this command, but do not get any arguments passed, it's possible that whatever script registered the association, didn't use the syntax for passing arguments. You can find the registered association and check the command to make sure it includes %* to pass all the parameters to the script.
You can find where the executable is by using where lua.exe command and then call that executable directly from the command line to see if it works.
Is it possible to start a command prompt from perl script using Win32::Process::Create package?
I am trying to start DOORS from perl script. The executable is present in C:\Program Files\DOORS\bin\runDOORS9.rck.
I need to start the runDOORS9.rck with the argument COL9 to change the Database.
Try the good old system() function. On Windows it would use the cmd.exe, the system shell, to execute the command.
Since what you try to launch doesn't seem to be an .exe file, potentially you would have to use the start command of the cmd.exe.
For example:
system(qq{start "" "C:\Program Files\DOORS\bin\runDOORS9.rck" COL9});
(The first "" is required due to quirky argument parsing of the Window's shell commands. See help start for more information.)
Problem: Windows XP is not passing command line arguments to perl scripts.
Symptom: a simple command like:
say "Argument 1 (\$ARGV[0]) is: $ARGV[0], argument 2 (\$ARGV[1]) is: $ARGV[1].";
Resulted in:
Use of uninitialized value $ARGV[0] in concatenation (.) or string at...
Solution:
The root problem is in Windows XP. The default method for starting perl passes only the first variable, which is the script name. Result is that $ARGV[0] is uninitialized.
The fix is to edit the Windows registry at:
\HKEY_CLASSES_ROOT\Perl\shell\Open\command
And make the entry:
"C:\Perl\bin\perl.exe" %*
Result is:
C:\whatever>perl argtest.pl 1 2
Argument 1 ($ARGV[0]) is: 1, argument 2 ($ARGV[1]) is: 2.
Thanks especially to David W who pointed me in the right direction.
Note that #ARGV in Perl is not quite like argv in C.
C Perl
Name of the program argv[0] $0
1st argument argv[1] $ARGV[0]
2nd argument argv[2] $ARGV[1]
n-th argument argv[n] $ARGV[n-1]
So if you provide one command line arguments to a Perl script, it will be found in $ARGV[0]. $ARGV[1] will be uninitialized.
Download Cygwin and test your code in the Cygwin environment. I bet this is a Windows issue. (If you're a Unix head, you'll like Cygwin because it gives you the Unix/Linux like environment on your Windows machine. I don't use Windows without it.)
Windows uses suffixes to determine what program opens what files. Is your Perl script called argtest, argtest.bat or argtest.pl?
On Windows, make sure all of your Perl scripts use the *.pl suffix, so Windows will use whatever Perl parameter to execute them. Windows doesn't use the shebang.
Another possible issue: On Windows XP, I had a problem with Perl scripts with parameters because Windows had this as an execution string:
perl %1
which would execute the Perl program with my script, but ignore the parameters. I had to change this to:
perl %*
Unfortunately, Windows Vista through Windows 8 changed the way this is set. However, I have Windows 7 and don't have this issue. I did make sure to install Perl under C:\Perl and not C:\Program Files\Perl because of the space in the directory name. I also have Strawberry Perl installed.
There is a special Windows environment variable called PATHEXT. This allows you to type in foo instead of foo.pl. If Windows can't see how to execute your file, Windows goes through %PATHEXT and tries appending various suffixes until it finds one that works. You might want to append .PL to that environment variable, so you can type in foo instead of foo.pl all the time.
There are two ways that Windows knows it is supposed to use Perl to execute a program.
The command line begins with the perl executable and the name of the script to be run is provided as a command line argument. This is how it works on Unix and other environments, too.
Your system associates one or more extensions, such as .pl, .pm, and/or .cgi with the Perl application, and Windows will launch Perl when you type a filename with one of those extensions or click on a file with one of those extensions in the Windows explorer.
You have invoked your script simply as
argtest 1 2
and not one of
perl argtest 1 2
argtest.pl 1 2
That makes me think that Perl is not the first application that gets to look at the file referred to by argtest. Perhaps there is a file called argtest.bat or argtest.exe which has the task of getting Perl to run your Perl code. For some reason this intermediate program is not passing the command line arguments that you provide on to the Perl application.
Provide the code for this intermediate file and we can help some more.
UPDATE: David W proposes a 3rd way -- setting the PATHEXT environment variable to inclue .pl files and invoking argtest from the command-line -- see his answer.
Then if Window's file association with the .pl extension was messed up, say, set as just C:\Dwimperl\perl\bin\perl" and not "C:\Dwimperl\perl\binperl %*" then the OP would get the behavior that he describes.
In perl file name is not part of the array of arguments. At least in the test I did you must remove ARGV[2] or pass three arguments, like argtest 1 2 3
I'm debugging a perl script with a lot of command-line arguments.
Is it possible to restart the execution of the script (using the R command of perl debugger) using a different set of arguments?
Since I've got a lot of breakpoints and watches defined I don't want to exit the debugger and restart it with the new args...
You could set a breakpoint at the start, restart it with R, and define the #ARGV you want in the debugger.
How can one pass command line arguments via file association in Vista 64?
I recently built a PC running Vista Ultimate 64-bit. I noticed several of the Perl scripts I transferred failed due to command-line arguments not being passed. As a simple test, I wrote the following (foo.pl):
#!/usr/bin/perl -w
use strict;
my $num_args = $#ARGV + 1;
print "${num_args} arguments read\n";
print "$^X\n" # to see what was being used
Running "foo.pl 1 2 3" undesirably yielded:
0 arguments read
C:\strawberry\perl\bin\perl.exe
Running "perl foo.pl 1 2 3" expectedly yielded:
3 arguments read
C:\strawberry\perl\bin\perl.exe
On my old Windows XP PC, both invocations returned 3 arguments. I documented more of my sleuthing here (win32.perl.org wiki talk), but I've yet to find a solution that works.
I've also tried ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi to no avail.
Any help would be appreciated. This is driving me batty.
I just tried ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi on my Vista 64 Ultimate and it worked.
F:\prog\perl>foo.pl 1 2 3
3 arguments read
C:\Perl64\bin\perl.exe
That means devio is right: it must be an "file association" issue;
On an explorer, right-click on your .pl file and ask "Open with": use the "Perl Command Line interpreter" and it will work (and select "always use this program to open this type of file").
To me, "Vista's file extension manager removed the ability to pass arguments to functions" seems wrong...
I do see:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Perl\shell\Open\command]
#="\"C:\\Perl64\\bin\\perl.exe\" \"%1\" %*"
Meaning if your installation did not put that kind of value in your registry, it is because:
you did not select the association during the setup of ActivePerl-5.10.0.1004-MSWin32-x64-287188.msi
or your account has not enough privilege to write anything in the registry.
Note:
it seems the regular extension manager on Vista does not pass argument (meaning \"C:\\Perl64\\bin\\perl.exe\" \"%1\" without the %* argument)
the registry addition is necessary as documented by the SO
Don't know about Vista and 64bits, but under "classic" versions of Windows you can edit the registry:
HKEY_CLASSES_ROOT\.pl
contains default string "Perl"
HKEY_CLASSES_ROOT\Perl\shell\open\command
contains the default string:
"C:\path-to\Perl\bin\perl.exe" "%1" %*
where %* is a macro for all parameters following the first. Probably the %* is missing.
Vista's file extension manager removed the ability to pass arguments to programs. You have to manually edit the registry like devio mentions (or use another program to edit file extensions).
Also interesting to know for a Perl beginner is that ARGV is case-sensitive ... just spend an hour trying to find out why my command line parameters are not passed, and it was just that I used argv[0] instead of ARGV[0] ...