User avatar
solar3000
Posts: 1051
Joined: Sat May 18, 2013 12:14 am

apache wont: script to call script and pass params

Mon Oct 30, 2017 6:46 pm

I have a script that's already running, we'll call it template1.cgi.

It takes parameters such as title, etc...in the form template1.cgi?title=My page&name=pair&etc...
That's fine.

Now I writing another script. And it doesn't matter what language. But for this example:

page.cgi
#!/usr/bin/perl
print "content-type: text/html\n\n";
@x = `/pathToScript/template1.cgi 'title=My Page&key=value, etc...' ` ;
print @x;

When page.cgi is run in the shell such as /bin/bash, I get a full page.
When page.cgi is called via a web browser and processed by apache, it will print out the template except that the parameters just disappear.

Any guesses?
Antikythera

User avatar
solar3000
Posts: 1051
Joined: Sat May 18, 2013 12:14 am

Re: apache wont: script to call script and pass params

Mon Oct 30, 2017 6:51 pm

Again, it could be a different script, it is still the same problem. It could be bash:

page.cgi
#!/bin/sh
echo "content-type: text/html";
echo
echo
echo `/pathToScript/template1.cgi 'title=My Page&key=value, etc...' ` ;
Antikythera

User avatar
DougieLawson
Posts: 36096
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: apache wont: script to call script and pass params

Mon Oct 30, 2017 7:00 pm

Install this: http://search.cpan.org/~szabgab/CGI-Sim ... /Simple.pm

Write your script like this:

Code: Select all

#!/usr/bin/perl

use CGI::Simple;
my $q = CGI::Simple->new;
print $q->header();
my $title = $q->param('title');
my $name = $q->param('name');

$q->print('<html><head><title>'.$title.'</title></head>');
$q->print('<body><h1>Hello '.$name.'<h1></body></html>')

Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
solar3000
Posts: 1051
Joined: Sat May 18, 2013 12:14 am

Re: apache wont: script to call script and pass params

Mon Oct 30, 2017 7:05 pm

No one understands me.

The script.cgi is already written. But in CGI.pm. And it works fine.

But I'm writing another script, just one line of code. It calls the script.cgi. So it would be a one line script that calls the script you just wrote.

My only guess is that its an apache security restriction.
Antikythera

Heater
Posts: 13269
Joined: Tue Jul 17, 2012 3:02 pm

Re: apache wont: script to call script and pass params

Mon Oct 30, 2017 7:23 pm

If in doubt, do not use Apache or PHP or Perl or CGI anything.

That is a lash up of technology from the late 1990's.

What actually is it you want to achieve?

User avatar
solar3000
Posts: 1051
Joined: Sat May 18, 2013 12:14 am

Re: apache wont: script to call script and pass params

Mon Oct 30, 2017 7:30 pm

What would you use?

I have stacks of scripts already working. I wrote them back when I was still alive. But I want to call them from within another script so I dont have to rewrite them.

Also, it seems it doesn't matter what script I use, bash, perl, python, NewReallyCoolLangage, etc...

My only guess is that it could be an apache config. I wouldn't even know what to put in a search engine because I'm too stoobid.
Antikythera

User avatar
DougieLawson
Posts: 36096
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: apache wont: script to call script and pass params

Mon Oct 30, 2017 7:58 pm

solar3000 wrote:
Mon Oct 30, 2017 7:05 pm
No one understands me.
Because, you're still not clearly stating the nature of your problem.

CGI programs are nothing special, I find that using HTML METHOD=POST is a bunch easier than METHOD=GET because the params are read from STDIN not from int ARGV/char * ARGC[].
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Heater
Posts: 13269
Joined: Tue Jul 17, 2012 3:02 pm

Re: apache wont: script to call script and pass params

Mon Oct 30, 2017 8:12 pm

solar3000,
What would you use?
Now a days I do everything in Javascript. Using node.js on the server end. Perhaps with nginx directing traffic.

I did the whole Apache, PHP, CGI thing back in 1990 something and was horrified at what a horrible mess it was. I swore never to do web development again. Until I discovered node.js...
I have stacks of scripts already working. I wrote them back when I was still alive.
I'm sorry to hear you are no longer alive.

Some how I doubt it :)
But I want to call them from within another script so I dont have to rewrite them.
OK. Admittedly I have no idea.

If you have CGI scripts in language X that calls language Y, that calls language Z... I think you are on your own in the chaos.

As far as I recall you should be able to run the whole stack from the command line, giving the right parameters, and the result should be what you want in HTML.

Do check you have the right permissions on everything.

User avatar
solar3000
Posts: 1051
Joined: Sat May 18, 2013 12:14 am

Re: apache wont: script to call script and pass params

Mon Oct 30, 2017 8:18 pm

OK. I'll look into this node.js thing.

I've been out of touch for about 10 years at least.


Wait a minute, drupal uses node.js. That's where I saw it, when updating drupal.
Antikythera

Return to “General discussion”