In addition to the other good suggestions already posted in this thread, I am hoping that you didn't call the program literally test, as that's the name of a shell built-in command.
Common beginner mistake. {grin}
That's why we tell our students to always invoke their first Perl program as ./program, so that even if they should name it test, it'll still work. Plus, for security reasons, most smart people
remove dot from their PATH anyway.
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply. | [reply] |
There are a lot of things to consider...
- `test` returns the output of the execution of "test", so your code is (trying to) run "test" and assigns all of its output to $execute; system executes the given command, so your code proceeds to (try to) run whatever "test" returned (oh, and "$var" is the same as $var). I take it that this is not what you are trying to do.
- In a normal, command-line environment, you have a list of directories to search for executables (it's usually the variable PATH, accessible from Perl as $ENV{PATH}). In a CGI environment, this list is usually empty, so if you want to execute a program you must specify the entire path (even if it is in the same dir as the CGI script).
- The CGI script is executed as the same user as the HTTP server, so it has different privileges than you. Keep this in mind when assigning permissions to your scripts/programs/files etc.
Now, short answers (use the one that is most appropriate):
- To get the output into a variable: $result=`/path/to/test -params`;
- To just execute it (sending output to STDOUT, STDERR): system('/path/to/test','-param1','-param2');
For more details (like how to redirect input/output, how to get into troubles with multiple variable expansion, etc) consult perlop (qx is the same as ``) and perlfunc (system)
--
dakkar - Mobilis in mobile
| [reply] [d/l] [select] |
It's a good idea to RTFM. There are several ways to execute a foreign program: qx// (aka backticks), system(), exec(), open().
It depends on what you want to do with that program: Do you only want to execute it, use system(). Do you only want to start it and leave your own program, use exec(). Do you want to communicate with it, use open(). Do you want to capture its output, use qx//.
--
http://fruiture.de
| [reply] |