i need to activate another script and pass 2 vars and have one returned.

Have I got the syntax correct AND why does it not see the script? It is in the same directory as the php script.

$mysearch="cats";
   $mytype = "zero";

    passthru ("/home/bookie/testbed/perlSOAP.cgi?fieldvalue=$mysearch&fieldsearch=$mytype&" , $response);
    return $response;
echo "response is $response";

I have tried the path on it's own AND as a full url

Dani AI

Generated

— that error shows what happened: passthru() handed the shell the whole string /home/bookie/testbed/perlSOAP.cgi?fieldvalue=cats... and the shell tried to execute a file with the ? and query attached. Query strings belong in an HTTP request, not in a filesystem path, so the OS reports “No such file or directory.” was also correct earlier about stopping execution with return — that was a separate issue you already removed.

If the CGI should be invoked through your webserver (typical for .cgi files) call it over HTTP instead of trying to execute a path with ?. Example using a simple HTTP fetch:

$url = 'http://your-host/testbed/perlSOAP.cgi?fieldvalue=' . urlencode($mysearch) . '&fieldsearch=' . urlencode($mytype);
$response = file_get_contents($url);
echo $response;

If instead you need to run the Perl script directly from PHP (not via the webserver), execute the interpreter and supply the CGI query string as the environment variable QUERY_STRING. Example pattern:

$qs = "fieldvalue=$mysearch&fieldsearch=$mytype";
$cmd = 'QUERY_STRING=' . escapeshellarg($qs) . ' /usr/bin/perl /home/bookie/testbed/perlSOAP.cgi 2>&1';
$response = shell_exec($cmd);

Checklist if it still fails:

  • Verify /home/bookie/testbed/perlSOAP.cgi exists and is executable (chmod +x) and has a correct shebang (#!/usr/bin/perl) that points to a real Perl binary.
  • Confirm the script works when requested in a browser (if using HTTP).
  • Check PHP disable_functions / open_basedir (these can block exec/passthru).
  • Capture stderr (2>&1) when using shell_exec to see errors, and review webserver error logs.
  • Always sanitize inputs (use urlencode or escapeshellarg) to avoid shell injection.

Using an HTTP call (cURL or file_get_contents) is usually the safest and simplest fix for a CGI that expects query-string input.

Recommended Answers

All 4 Replies

i need to activate another script and pass 2 vars and have one returned.

Have I got the syntax correct AND why does it not see the script? It is in the same directory as the php script.

$mysearch="cats";
   $mytype = "zero";

    passthru ("/home/bookie/testbed/perlSOAP.cgi?fieldvalue=$mysearch&fieldsearch=$mytype&" , $response);
    return $response;
echo "response is $response";

I have tried the path on it's own AND as a full url

According to the documentation, such may be the case if PHP is in safe mode, is this true?

According to the documentation, such may be the case if PHP is in safe mode, is this true?

It has nothing to do with safe mode, he's killing the script before it can echo because of return $response;

removed return $response and still:

sh: /home/bookie/testbed/perlSOAP.cgi?fieldvalue=cats: No such file or directory
and I am not in safemode

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.