problem in calling program in my perl script

D

debbie523

I have a program named p1.c, it works file in windows(the p1.exe works
file).
But it does not work in my perl script.

Part of my script is as following:

#!/bin/perl -w

use CGI;

$query=new CGI;

my $nominees=$query->param('n1');
my $nominations=$query->param('n2');
my $leaders=$query->param('n3');
my $followers=$query->param('n4');
my $filename=$query->param('f1');
exec ("p1.exe");

print $query->header();
print "<html><body bgcolor=black text=lime>\n";
print "<center><br><br><br><H2>get data and run the
program</H2>\n<hr>";
print "<form action='p1.cgi' method='post'>";
print "<h4>nominees = <input type='text' value=$nominees></h4>\n";
print "<h4>nominations = <input type='text'
value=$nominations></h4>\n";
print "<h4>leaders = <input type='text' value=$leaders></h4>\n";
print "<h4>followers = <input type='text' value=$followers></h4>\n";
print "<br><input type='submit' name='s1' value='ok'>";
print "</form>";
print "<h4>filename = $filename</h4>\n";
print "</center>";
print "</body></html>\n";


ps:the function of p1.exe is writing word "welcome" to a text file
"op.txt".

I appreciate your help.
 
S

Sherm Pendley

debbie523 said:
I have a program named p1.c, it works file in windows(the p1.exe works
file).
But it does not work in my perl script.

Please define "does not work".

Part of my script is as following:

#!/bin/perl -w

use CGI;

$query=new CGI;

my $nominees=$query->param('n1');
my $nominations=$query->param('n2');
my $leaders=$query->param('n3');
my $followers=$query->param('n4');
my $filename=$query->param('f1');
exec ("p1.exe");

Check the documentation for the function you're using. exec() does not do
what you think it does.

sherm--
 
K

krakle

debbie523 said:
I have a program named p1.c, it works file in windows(the p1.exe works
file).
But it does not work in my perl script.

Part of my script is as following:

#!/bin/perl -w

use CGI;

Where is "use strict;". MANY problems can be resolved with using this
pragma... So:

#!/bin/perl -w

use strict; # Just keep it
use warnings; # For testing
use diagnostics; # For testing

use CGI;
$query=new CGI;

my $query = new CGI;
my $nominees=$query->param('n1');
my $nominations=$query->param('n2');
my $leaders=$query->param('n3');
my $followers=$query->param('n4');
my $filename=$query->param('f1');

Although not *important* for running code... It helps if your code is
more readable

my $nominees = $query->param('n1');
my $nominations = $query->param('n2');
my $leaders = $query->param('n3');
my $followers = $query->param('n4');
my $filename = $query->param('f1');

exec ("p1.exe");

Does p1.exe even exist to execute?
print $query->header();
print "<html><body bgcolor=black text=lime>\n";
print "<center><br><br><br><H2>get data and run the
program</H2>\n<hr>";
print "<form action='p1.cgi' method='post'>";
print "<h4>nominees = <input type='text' value=$nominees></h4>\n";
print "<h4>nominations = <input type='text'
value=$nominations></h4>\n";
print "<h4>leaders = <input type='text' value=$leaders></h4>\n";
print "<h4>followers = <input type='text' value=$followers></h4>\n";
print "<br><input type='submit' name='s1' value='ok'>";
print "</form>";
print "<h4>filename = $filename</h4>\n";
print "</center>";
print "</body></html>\n";

This type of printing HTML seems like a waste of time to me...

print $query->header();

print <<End_Html;

<html>
<body bgcolor=black text=lime>
<center>
<br><br><br>
<H2>get data and run the program</H2>
<hr>
<form action='p1.cgi' method='post'>
<h4>nominees = <input type='text' value=$nominees></h4>
<h4>nominations = <input type='text' value=$nominations></h4>
<h4>leaders = <input type='text' value=$leaders></h4>
<h4>followers = <input type='text' value=$followers></h4>
<br><input type='submit' name='s1' value='ok'>
</form>
<h4>filename = $filename</h4>
</center>
</body>
</html>

End_Html
ps:the function of p1.exe is writing word "welcome" to a text file
"op.txt".

I appreciate your help.

What doesn't work?
What does p1.exe do?

You do realise ALL of your HTML inputs do NOT have names YET your Perl
script is attempting to get the queries by name... That's one thing
that doesn't work for you...
 
D

debbie523

Where is "use strict;". MANY problems can be resolved with using this
pragma... So:

#!/bin/perl -w

use strict; # Just keep it
use warnings; # For testing
use diagnostics; # For testing

use CGI;


my $query = new CGI;


Although not *important* for running code... It helps if your code is
more readable

my $nominees = $query->param('n1');
my $nominations = $query->param('n2');
my $leaders = $query->param('n3');
my $followers = $query->param('n4');
my $filename = $query->param('f1');



Does p1.exe even exist to execute?
yes, it does exist. But it looks like not called by my perl program.
Because I can't see welcome printed in my op.txt file. But if I run it
in windows, it works good.
 
D

David Squire

yes, it does exist. But it looks like not called by my perl program.
Because I can't see welcome printed in my op.txt file. But if I run it
in windows, it works good.


Your problem was already solved by an earlier poster. exec is not what
you think. RTFM.

DS
 
K

krakle

debbie523 said:
yes, it does exist. But it looks like not called by my perl program.
Because I can't see welcome printed in my op.txt file. But if I run it
in windows, it works good.

<input type="text" name="president" value="George Bush">

The form inputs name is "president". To get the value (George Bush) in
a Perl CGI script you must fetch the parameter by name like so:

my $president = $query->param("president");

print $president; # Prints George Bush

Your script is attempting to fetch parameters by names that don't
exist. Your inputs should include the "name" attribute like the above
example..
 

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,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top