I am somehow puzzled why you want to use CGI to do command-line processing. Nevertheless CGI scripts can run as normal programs. You will need to drop the question mark before uid. Otherwise user1 is treated as the value of the "?uid" variable.
use strict;
use CGI;
my $q = new CGI;
my $q_uid = $q->param('uid');
print "$q_uid\n";
You call the script with -
script.cgi uid=user1
| [reply] [d/l] [select] |
Take a look at the -s switch in perlrun or use the more sane Getopt::Long approach. Don't use a drill to pick your nose. (for obvious reasons)
| [reply] [d/l] |
I'd drop the question mark from the command line to solve your problem, but then, why should you use a CGI interface for the program you're launching in the background?
Apart for this, I' don't like much the idea of launching another process from a web page. You sure there is no smarter way to do it, like having a process running and queuing requests to it? As you don't know when the process will end, I presume what you need to do is not synchronous. You could just add a flag on a table (or write a flag-file in a directory) and then a single process would look for existing flags and process them one at a time.
This has the adventages that you 'pay' for program startup only once (process creation and code compilation, if it's in Perl), you have no racing conditions to take care of, and you can write readable logs (as it will process one thing at a time), and as you have only one instance running there is only one copy of the program in RAM at a given time.
My 0.02 euros
| [reply] |
i think you need to learn the difference between a cgi program, which is a program that processes and/or generates web pages, and a normal (non-cgi) program. A CGI program takes its' parameters from HTML forms and receives them via param{'var_name'} call. This is the CGI interface. When you are calling your background process directly from another program, the interface is standard (not redirected) input/output and @ARGV to get at arguments passed to it. Mind you, you have to be very careful in the design of both the CGI program and your background process, as the web users will potentially create many instances of those programs in memory simultaneously. Therefore, if your programs deal with any files, they must be written as not to interfere with each other or corrupt files.
I recommend that you borrow/buy a book on perl CGI to learn a great deal more....CGI programs, i.e. perl programs that "use CGI;" have their standard input,output,and error handles re-directed. it's like switching from programming for a console app. to a windows based app., input/output and standard arguments are handled differently.
| [reply] |
Thanks very much for your replies.
I will look into the options in more detail and work on it.
I like the option of using a file or table and let only
one instance of the program running.
I might have said it wrong when I said that I want to run
a CGI program in batch. It is just a perl program.
I tried using the @ARGV and STDIN, but I was not
successful in transfering the data. I was able to pass the
file name, but not a variable with data or data itself.
Can you give a sample code or how to use these to pass
parameters (data or variable) to other program than the
file names.
Thanks very much for you help! | [reply] |