Re: system() or exec() in CGI scripts (use Win32)
by grinder (Bishop) on Sep 09, 2003 at 11:47 UTC
|
fork and exec, despite the heroic efforts of a number of people, don't really work on Win32 platforms. You're much better off using Perl's Win32 interface. Something like the following will get you on your way:
use Win32;
use Win32::Process;
my $ie;
Win32::Process::Create(
$ie,
'C:/Program Files/Internet Explorer/iexplore.exe',
'http://localhost/foo.html',
0,
NORMAL_PRIORITY_CLASS,
'.'
) or print Win32::GetLastError();
Needless to say, this won't run on Unix, but if you are careful you can encapsulate this, and do the Right Thing according to platform.
| [reply] [d/l] |
|
| [reply] |
|
| [reply] |
Re: system() or exec() in CGI scripts
by Abigail-II (Bishop) on Sep 09, 2003 at 10:55 UTC
|
system and exec do two different things. system starts up
another process, waits for it to finish, and then continues
with the rest of the original process. exec replaces
the current process with a new one.
However, if explorer.exe starts on the machine, but doesn't
exhibit the wanted behaviour, it's not a matter of system
vs exec. In fact, it's unlikely to be a Perl problem.
What happens if you run the command from the command line?
What happens if you run the command from a CGI program
written in a different language than Perl? Could it be that
the webserver sets up an environment that iexplorer.exe doesn't
like?
Abigail | [reply] |
|
| [reply] |
|
Then it's a CGI issue, and not a Perl issue. Your server
sets up a different environment (variables, UID, permissions,
limits) than you have from the command line. At least one
of these differences prohibits your exe file to behave
differently.
Abigail
| [reply] |
Re: system() or exec() in CGI scripts
by Roger (Parson) on Sep 09, 2003 at 12:08 UTC
|
This is because the perl CGI script on your web server is run by mod_perl module, not perl. There is a specific method for starting a new process in apache CGI, which would look somewhat like the following:
use Apache::SubProcess ();
$command = "C:\\Windows\\iexplorer.exe";
Apache::SubProcess::spawn_proc_prog(undef, $command);
| [reply] [d/l] |
Re: system() or exec() in CGI scripts
by bm (Hermit) on Sep 09, 2003 at 11:09 UTC
|
I want to remotely open a Internet Explorer window.
Are you saying that you would like a new browser window to open on the user's computer that is running your CGI script? If so, you are chasing a red herring. Executing iexplorer.exe will start a new browser window on the server. You probably want it to start on the client.
--
bm | [reply] |
|
| [reply] |
|
| [reply] [d/l] |