Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with error: Unrecognized character \x7F at db.cgi line 1.

Status
Not open for further replies.

kaancho12

Technical User
Feb 22, 2005
191
hi,
ok, i have a cgi program which is supposed to take a xml file and go through it and return some string data. i dont know the variables of how the cgi program is executed.
But I need to upload a xml file to this program through php and i have been using curl to do this. When i try to execute php i get the error "premature end of script headers: db.cgi".
So, i tried to execute the program by going to the folder where the cgi program exists and giving it this command (it accepts two parameters):
perl db.cgi cApp=1 db=prod xmlfile.xml

But, i get the error:
Unrecognized character \x7F at db.cgi line 1.

Now, is there anything that I need to be doing to execute the cgi program at command prompt. Btw I am on a linux machine.

// Either 'http' or 'https'. 'https' is only an option if OpenSSH
// is available on your system. Check phpinfo() to see whether
// HTTPS is available.
$HTTP_method = 'http';

// IP-resolvable FQDN of the server
$hostname = 'localhost';

// Path on that server to the CGI
$cgi = '/cgi-bin/db.cgi';

// Array of data. The foreach loop below is going to construct a field/data
// string like the one you see in the URL of a GET-method CGI.
$my_data = array (
'cApp' => '1',
'db' => 'prod'
);

// This section constructs the field/value pairs of the form
// field1=value1&field2=value2&field3=value3
$data_string = " ";
$add_ampersand = FALSE;
foreach ($my_data as $key => $value)
{
if ($add_ampersand)
{
$data_string .= '&';
}
$data_string .= $key . '=' . $value;
$add_ampersand = TRUE;
}
//Set a file handle
$fp = file('/var/
// Get a CURL handle
$curl_handle = curl_init();

// Tell CURL the URL of the CGI
curl_setopt ($curl_handle, CURLOPT_URL, $HTTP_method . '://' . $hostname . $cgi);

// This section sets various options. See // for more details
curl_setopt ($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, 1);
curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data_string);
curl_setopt ($curl_handle, CURLOPT_INFILE,$fp);
curl_setopt ($curl_handle, CURLOPT_USERPWD,"user:passwd");

// Perform the POST and get the data returned by the server.
$result = curl_exec($curl_handle) or die ("There has been an error");

// Close the CURL handle
curl_close ($curl_handle);
 
Whats your shebang line look like

Code:
#!/usr/bin/perl

\x7F is 127 which I can't remember off hand, but perl doesn't expect it, so if you find out where and what it is, it should be easy to remove ;-)

--Paul



cigless ...
 
well,
the cgi script start's out with funky characters and i am not sure why this is so. does this mean that there is something wrong with cgi script?
here's the starting lines from cgi script if u can make any sense out of it.

Ã<85>d÷ÿÿÃ-^E^Hÿµd÷ÿÿÿµ<94>÷ÿÿhà -^E^Hè÷Ã<83>Ã
ÿÿuôè!Ãÿÿ<83>à ^P<83>ì^Hhø-^E^Hÿuôè^DÃÿÿ<83>Ã
^PP<8b><85><94>÷ÿÿ;<85><84>÷ÿÿu^LÃ<85>`÷ÿÿÃ-^E^Hë ^P<89><85><94>÷ÿÿ<83>½<94>÷ÿÿ^@xR<83>ì^Hÿµ<94>÷ÿÃ
<8b>E^H<8b>^@<89>EôëQ<8b>E^H<8b>^@<89>Eü<83>ì^LÿuüèÃýÿÿ<83>Ã
ÿÿ<83>à ^DPèb¿ÿÿ


 
That's corruption that is, save the file as crupt.pl, and edit those lines out of the script until the first line is
Code:
#!/usr/bin/perl
or whatever your path to perl is

HTH
--Paul

cigless ...
 
well,i should have told u in the earlier post --there seems to be some coding after a while but the code in general does not contain the shebang line !#/usr/bin/perl/
 
Therein lies the problem, is this an obfuscated perl script, or a compiled exe?

--Paul

cigless ...
 
its a compiled exe most probably.

ko12
 
path to cgi-bin, shouldn't be
/cgi-bin/db.cgi I'm guessing

on *nix run an exe ./db.cgi in the directory its in.

I'm thinking the path to cgi-bin could be the problem
Code:
$cgi="/cgi-bin/"; // if that doesn't work remove the trailing slash (it could be added in later)

Try that and let us know how you got on

--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top