473,881 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Win32 - forked process doesn't create a Window

RL
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\syst em32 notepad.exe
FORKME: Forking perl createme.pl C:\Windows\syst em32 notepad.exe
CREATEME: Starting C:\Windows\syst em32\notepad.ex e
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\USE RS"
<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?a ction=spawn" method="post"
enctype="multip art/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\\sy stem32 notepad.exe";
print "SPAWNBOSS: Running $command<br>\n" ;
system("$comman d");
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::FormatMe ssage( Win32::GetLastE rror() );
}
print("CREATEME : Starting $ARGV[0]\\$ARGV[1]<br>\n");
Win32::Process: :Create($Proces sObj,
"$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

Jul 19 '05 #1
2 5001
In article <rP************ ******@news20.b ellglobal.com>, RL
<lr*******@hotm ail.com> wrote:
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\syst em32 notepad.exe
FORKME: Forking perl createme.pl C:\Windows\syst em32 notepad.exe
CREATEME: Starting C:\Windows\syst em32\notepad.ex e
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
Since I don't work on Windows, I am afraid I can't help you too much. I
can, however, point out some oddities in your program.

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\USE RS"
<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?a ction=spawn" method="post"
enctype="multip art/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\\sy stem32 notepad.exe";
print "SPAWNBOSS: Running $command<br>\n" ;
system("$comman d");
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;
fork() returns a non-zero pid (that of the child) to the parent and
returns zero to the child. Thus, you are exec'ing from the parent
process and the child just dies with an error message. You can probably
eliminate the fork and this entire script, since you are not using the
child process. Do you want the parent process to return the completed
web page to the browser while notepad.exe runs? Then you should run
notepad.exe from the child.

=============== =============== =======
CREATEME.PL
#!d:/apps/perl/bin/perl.exe
use Win32::Process;
use IO::Handle;
STDOUT->autoflush(1) ;
STDERR->autoflush(1) ;
sub ErrorReport{
print Win32::FormatMe ssage( Win32::GetLastE rror() );
}
print("CREATEME : Starting $ARGV[0]\\$ARGV[1]<br>\n");
Win32::Process: :Create($Proces sObj,
"$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


Another tip: make sure you can run your CGI script from the command
line before you try to execute it from the web server, if you have
command line access to the server.

FYI: this newsgroup is defunct. Try comp.lang.perl. misc in the future
for better response.
Jul 19 '05 #2
RL
Hi Jim,

You are correct, I don't need the fork.

Also, just realized I forgot to add the createme.pl program
=============== =============== =======
CREATEME.PL
#!d:/apps/perl/bin/perl.exe
use Win32::Process;
use IO::Handle;
STDOUT->autoflush(1) ;
STDERR->autoflush(1) ;
sub ErrorReport{
print Win32::FormatMe ssage( Win32::GetLastE rror() );
}
print("CREATEME : Starting $ARGV[0]\\$ARGV[1]<br>\n");
Win32::Process: :Create($Proces sObj,
"$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;
=============== =============== =======

"Jim Gibson" <jg*****@mail.a rc.nasa.gov> wrote in message
news:0502200417 17002619%jg**** *@mail.arc.nasa .gov...
In article <rP************ ******@news20.b ellglobal.com>, RL
<lr*******@hotm ail.com> wrote:
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\syst em32 notepad.exe
FORKME: Forking perl createme.pl C:\Windows\syst em32 notepad.exe
CREATEME: Starting C:\Windows\syst em32\notepad.ex e
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


Since I don't work on Windows, I am afraid I can't help you too much. I
can, however, point out some oddities in your program.

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\USE RS"
<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?a ction=spawn" method="post"
enctype="multip art/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\\sy stem32 notepad.exe";
print "SPAWNBOSS: Running $command<br>\n" ;
system("$comman d");
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;


fork() returns a non-zero pid (that of the child) to the parent and
returns zero to the child. Thus, you are exec'ing from the parent
process and the child just dies with an error message. You can probably
eliminate the fork and this entire script, since you are not using the
child process. Do you want the parent process to return the completed
web page to the browser while notepad.exe runs? Then you should run
notepad.exe from the child.

=============== =============== =======
CREATEME.PL
#!d:/apps/perl/bin/perl.exe
use Win32::Process;
use IO::Handle;
STDOUT->autoflush(1) ;
STDERR->autoflush(1) ;
sub ErrorReport{
print Win32::FormatMe ssage( Win32::GetLastE rror() );
}
print("CREATEME : Starting $ARGV[0]\\$ARGV[1]<br>\n");
Win32::Process: :Create($Proces sObj,
"$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


Another tip: make sure you can run your CGI script from the command
line before you try to execute it from the web server, if you have
command line access to the server.

FYI: this newsgroup is defunct. Try comp.lang.perl. misc in the future
for better response.

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
13103
by: John Lin | last post by:
Howdy, I want to know how to tell if a forked process is done. Actually, my real question is that I want to run a shell script inside of a python script, and after the shell script has finished running, I want to do more stuff *condition* on the fact that the shell script has finished running, inside the same python script. The only way I can think of is to fork a process and then call the
2
6788
by: Paolo | last post by:
There is something I can't understand which is the following. I have a system command which runs a commandline to unzip a file: my $Out = system ( $rootPath."bin/bin/gunzip -dfc ". $SourceFilePath." > ".$rootPath.$DestinationPath.".txt"); This works fine. since I would like to make it parallel and run 4 processes at a time I wrote this code:
1
3486
by: Alexander N. Spitzer | last post by:
I am trying to write a program that will fork a process, and execute the given task... the catch is that if it runs too long, I want to clean it up. this seemed pretty straight forward with a single executable being run from the fork. The problem I am having now is that if I call a shell scripts, then lets say calls "xterm &", after the timeout has occurred, I kill the shell script, but the xterm is still running... I cannot seem to kill...
2
1548
by: James Colannino | last post by:
Hey everyone. I'm writing a small application in Python that uses os.fork() to create a separate process in which another application is run in the background. The problem is that I need to know whether or not that separate application managed to start and return from within the parent appropriately. Here's, roughly, a pseudo example of what I want to do (I know the code itself is not correct): def function(): pid = os.fork()
3
1521
by: Gil | last post by:
I need to create a web page in which its content should be controlled by some win32 application. this application may add or remove some gif images from the page and it should be smooth as possible as can. Can someone here direct me how to start that. Thanks in advance Gil
0
2445
by: jbenezech | last post by:
Hi all , I have a perl/java app running under Win32. The application consists of a perl service (Win32::Daemon) and of java classes. The perl service calls every xx hours java classes to perform some action. The java call looks like this: Win32::SetChildShowWindow(0); Win32::Process::Create(
1
5689
by: chriskent | last post by:
Hi, I have an unusual situation whereby we create a Window during initialisation. We have used this code for many years and have found one unusual case with a customer when the RegiterClass fails and then the following CreateWindow also fails, making our process timeout and fail. My real problem is trying to understand what is causing the RegisterClass to fail and I believe that this function does not set the last error so GetLastError()...
3
12703
by: Firecore | last post by:
Does anyone know how to use this? I was browsing a few tutorials on the net, and I saw one that shows how to display stuff on the screen. I added a few events. This is my code: #include <windows.h> // FOR ANY DIFFICULTIES, REFER TO THE MSDN. IT IS VERY USEFUL. HWND hwndMain; LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);//CALLBACK function prototype
1
2629
by: Tension | last post by:
Hi, I am trying to run a Tornado simulator with Perl. The command line in an ordinary Windows command window looks like this: "C:\Tornado\target\config\simpc\vxWorks.exe /r32000000" Which I then wish to run inside a Perl script. This then becomes: Win32::Process::Create($vxsim_process_object, "C:\\Tornado\\target\\config\\simpc\\vxWorks.exe",
0
9928
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11100
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10816
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10402
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7111
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5781
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.