Win32 - forked process doesn't create a Window

From: RL (lrlemieux_at_hotmail.com)
Date: 02/02/04


Date: Sun, 1 Feb 2004 20:35:28 -0500

Hello Perl gurus,

1. I have a web page where I can push a button (dospawn.html).
2. This button calls a CGI script (spawnboss.cgi)
3. spawnboss.cgi calls a forking perl script (forkme.pl)
4. forkme.pl calls the process creation script (createme.pl)
5. createme.pl creates my notepad.exe process, but no window shows up on my
PC.

The result on my web browser is:
SPAWNBOSS: Running perl forkme.pl C:\Windows\system32 notepad.exe
FORKME: Forking perl createme.pl C:\Windows\system32 notepad.exe
CREATEME: Starting C:\Windows\system32\notepad.exe
CREATEME: process notepad.exe is running

When I kill the notepad.exe from my Task Manager,
I then get on my web browser the final output:
CREATEME: process notepad.exe was ended

The only thing missing is the graphical window for NOTEPAD so I can type
into it.

Thanks for your assistance :)
Rob

Details following...

Have the latest installed version of ActivePerl 5.8.2.
The web page is on my personal Apache web server 2.0.47.
http://localhost/~test/dospawn.html
Configured for CGI with:
=====================================
LoadModule cgi_module modules/mod_cgi.so
ScriptAlias /cgi-bin/ "D:/Apps/Apache2/cgi-bin/"
UserDir "D:\Web\USERS"
<Directory "D:/Web/USERS/test/cgi-bin/">
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>
AddHandler cgi-script .cgi .pl
=====================================

The files are as follows:
=====================================
DOSPAWN.HTML
<html><body>
<form action="cgi-bin/spawnboss.cgi?action=spawn" method="post"
enctype="multipart/form-data">
<input type=hidden name="action" value="spawn">
<input type="submit" value="Spawn NOTEPAD">
</form>
</body></html>
=====================================
SPAWNBOSS.CGI
#!d:/apps/perl/bin/perl.exe
use CGI qw/:standard :html3/;
&spawn if (param('action') eq 'spawn'); # Spawn a process
exit;
sub spawn {
  print "Content-type: text/html\n\n";
  print "<HTML><BODY>\n";
  $command = "perl forkme.pl C:\\Windows\\system32 notepad.exe";
  print "SPAWNBOSS: Running $command<br>\n";
  system("$command");
  print "</BODY></HTML>\n";
  return;
}
=====================================
FORKME.PL
#!d:/apps/perl/bin/perl.exe
$command = "perl createme.pl $ARGV[0] $ARGV[1]";
if ($pid = fork) {
  print "FORKME: Forking $command<br>\n";
  exec "$command";
  die "couldn't exec $command : $!";
}
else {
  die "DO_RUNME: fork failed: $!";
}
exit;
=====================================
CREATEME.PL
#!d:/apps/perl/bin/perl.exe
use Win32::Process;
use IO::Handle;
STDOUT->autoflush(1);
STDERR->autoflush(1);
sub ErrorReport{
  print Win32::FormatMessage( Win32::GetLastError() );
}
print("CREATEME: Starting $ARGV[0]\\$ARGV[1]<br>\n");
Win32::Process::Create($ProcessObj,
  "$ARGV[0]\\$ARGV[1]",
  "$ARGV[1]",
  1,
  NORMAL_PRIORITY_CLASS,
  "$ARGV[0]\\")|| die ErrorReport();
print("CREATEME: process $ARGV[1] is running<br>\n");
$ProcessObj->Wait(INFINITE);
print("CREATEME: process $ARGV[1] was ended<br>\n");
exit;
=====================================
The END



Relevant Pages

  • Re: browser output
    ... >> with regards to your EXIT comment, if i hear correctly, just make sure ... >> your script is at the bottom of the file and just ... A CGI program runs from A to Z, ...
    (comp.lang.perl.misc)
  • Re: browser output
    ... >> with regards to your EXIT comment, if i hear correctly, just make sure ... >> your script is at the bottom of the file and just ... A CGI program runs from A to Z, ... I think that using 'exit' halfway your program is as natural ...
    (comp.lang.perl.misc)
  • Re: Key-passing from PHP to TCL CGI script - how is it done (web security issue)?
    ... TCL v.8.3 ... set hasEnteredTrivia 0 ... # NEW 8/7/2004 USE PHP (AS CGI) TO CHECK IF USER IS ATTEMPTING TO ENTER ... # USE REMOTE PHP SCRIPT TO CHECK FOR REPOSTING ...
    (comp.lang.tcl)
  • Re: Changing Passwords through the web (fwd)
    ... I use a CGI script that uses the poppassd and python ports on my small ... alert; ...
    (FreeBSD-Security)
  • Re: Help with a stragegy for diagnosis
    ... I have a Perl CGI that has work for years. ... first failure and before the second. ... A strategy would be to write tests for the script until you get the same ...
    (comp.lang.perl.moderated)