system command won't let go

R

rallabs

Dear perl experts:
I am having some difficulties with the 'system' command. I am trying
to use it to run a C
program that has already been compiled. If I am at the UNIX command
prompt I can run the program by typing in "~/runsgood.exe". The
program then prompts me for an input file for it to use. It says:
ENTER INPUT FILE NAME WITHOUT .in EXTENSION. and when I obey I get
nothing at the prompt except there will be
a new file in my current directory with the same root as I gave it but
a .out extension. I can also run the program by preparing a file
containing the root name including the path: ~/runsgood.exe<point. The
file "point" is a single
line: ~/directory/root . When I run the program this way I see the
prompt but the program gets its answer from the file "point". The
problem is it doesn't do this from the sys command. Here is the script
I use to try it:

#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw:)standard -no_xhtml);
use diagnostics;
my $co = new CGI;
my $newID=cookie('newID');
system "sed s/old/$newID/ point_old >point.$newID";
system "~/runsgood.exe<point.$newID";
print $co->redirect('~/cgi-bin/done.cgi');

and when I run the script here's what appears in a browser window:

ENTER INPUT FILE NAME WITHOUT .in EXTENSION

Status: 302 Moved
Location: ~/cgi-bin/done.cgi


The prompt from runsgood.exe appears, just as it does when I run it
interactively. The program does its job and the output does appear in
my directory as it should, but it cannot get to the last line for some
reason. Does anybody know how to stop this? I was hoping that I would
get the prompt to disappear because I had no header in the script, and
I hoped that it would move on to the script 'done.cgi' but no such
luck. I need to find a way to get to that last script. Thanks for any
help.

mike
 
B

Brian McCauley

I am having some difficulties with the 'system' command.
system "~/runsgood.exe<point.$newID";
and when I run the script here's what appears in a browser window:

ENTER INPUT FILE NAME WITHOUT .in EXTENSION

Status: 302 Moved
Location: ~/cgi-bin/done.cgi


The prompt from runsgood.exe appears, just as it does when I run it
interactively. The program does its job and the output does appear in
my directory as it should, but it cannot get to the last line for some
reason.

I have no idea what you meant by "it cannot get to the last line".
Does anybody know how to stop this?

If you are asking how you can redirect the output of the ~/runsgood.exe
process then why don't you just use a shell redirect as you did to
redirect the input?

system "~/runsgood.exe said:
I was hoping that I would
get the prompt to disappear because I had no header in the script,

I have no idea what you meant by that.
 
B

Brian McCauley

use CGI qw:)standard -no_xhtml);
my $co = new CGI;

You should probably decide which of the GCI APIs you are using,
"standard" or OO.
system "sed s/old/$newID/ point_old >point.$newID";

You know Perl is quite a powerfull text processing language in itself.
Why do you feel the need to use sed?
system "~/runsgood.exe<point.$newID";
print $co->redirect('~/cgi-bin/done.cgi');

and when I run the script here's what appears in a browser window:

ENTER INPUT FILE NAME WITHOUT .in EXTENSION

Status: 302 Moved
Location: ~/cgi-bin/done.cgi

What web server are you using? I would have expected to see an error
from the web server saying that the GCI script did not generate valid
headers.
 
T

Tad McClellan

system "~/runsgood.exe<point.$newID";

I was hoping that I would
get the prompt to disappear


Then redirect the program's STDOUT:

system "~/runsgood.exe >/dev/null <point.$newID";
 
M

Mumia W.

[...]
print $co->redirect('~/cgi-bin/done.cgi');

and when I run the script here's what appears in a browser window:

ENTER INPUT FILE NAME WITHOUT .in EXTENSION

Status: 302 Moved
Location: ~/cgi-bin/done.cgi
[...]

This (~) is your problem. Location headers are supposed to be
absolute, not relative, and tilde (~) has no meaning in a web
server context.

print $co->redirect('http://www.mysite.com/cgi-bin/done.cgi');
 
R

rallabs

I have no idea what you meant by "it cannot get to the last line".

The last line of the script, which should take me to the page named
'done.cgi'
If you are asking how you can redirect the output of the ~/runsgood.exe
process then why don't you just use a shell redirect as you did to
redirect the input?

I don't want to redirect the output of runsgood. I merely want the
computer to take me to the next line, a redirect to 'done.cgi'.
I have no idea what you meant by that.

When I put an & after the system command:

system "~/runsgood.exe<point.$newID" &
the new process runs in the background and the script continues on to
the 'last line' to execute the redirect command to 'done.cgi'. The
book 'Learning Perl' at least the way I interpret it says that while
the 'system' function runs, Perl pauses and waits for it to finish and
then moves on, so it would seem that the original script I posted (with
no &) should do this: wait for 'runsgood.exe' to finish and then go to
'done.cgi'. I don't understand it. Thanks for the advice.
mike
 
R

rallabs

Tad said:
Then redirect the program's STDOUT:

system "~/runsgood.exe >/dev/null <point.$newID";

Thanks very much. This does stop the STDOUT output from 'runsgood.exe'
from appearing on the screen. The script also then goes on to run the
last line of my script. Running the process in the background also
accomplishes this. I guess there really is "more than one way to do
it" Don't ask me where the STDOUT goes to when I run 'system' in the
background. Thanks again.
 
B

Brian McCauley

Thanks very much. This does stop the STDOUT output from 'runsgood.exe'
from appearing on the screen. The script also then goes on to run the
last line of my script. Running the process in the background also
accomplishes this. I guess there really is "more than one way to do
it"

Yes, but some are conceptually flawed even if they happen to work.

You don't want A to happen _before_ B.

(A is the output of the ~/runsgood.exe being sent to the web server
process. B is the redirect header being sent to the web server
process).

You can try the following

1. Prevent A happening (what Tad and I suggest)
2. Cause B to happen and then cause A to happen.
3. Cause A and B to happen in paralell and rely on the fact that A
takes longer so its effect is seen after B.

Option 3, your "Running the process in the background" option works,
but any solution based on a race condtion is conceptually flawed.
Don't ask me where the STDOUT goes to when I run 'system' in the
background.

I won't ask you, I'll tell you. It goes into the HTTP response body
because it arrives at the web server process after the headers.

Solution 2, generating the redirect header and then running
~/runsgood.exe without bothering to redirect the output would give the
same result as option 3 without the race condition.

Since you don't actually _want_ A to happen at all then solution 1 has
to be the best.
 
R

rallabs

Brian said:
Yes, but some are conceptually flawed even if they happen to work.

You don't want A to happen _before_ B.

(A is the output of the ~/runsgood.exe being sent to the web server
process. B is the redirect header being sent to the web server
process).

You can try the following

1. Prevent A happening (what Tad and I suggest)
2. Cause B to happen and then cause A to happen.
3. Cause A and B to happen in paralell and rely on the fact that A
takes longer so its effect is seen after B.

Option 3, your "Running the process in the background" option works,
but any solution based on a race condtion is conceptually flawed.


I won't ask you, I'll tell you. It goes into the HTTP response body
because it arrives at the web server process after the headers.

Solution 2, generating the redirect header and then running
~/runsgood.exe without bothering to redirect the output would give the
same result as option 3 without the race condition.

Since you don't actually _want_ A to happen at all then solution 1 has
to be the best.

Thanks very much to you and to Tad for the answer and the explanations.
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top