LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-29-2020, 11:38 PM   #31
hpdp
LQ Newbie
 
Registered: Jan 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled

>> when run from the command line?
>> What, specifically, happens in the browser? Nothing? An error? A blank page?

run from command line, ./mycode.cgi, the output
Quote:
Content-TYPE: image/svg+xml

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg ....
</svg>
call from browser, http://.../mycode.cgi, it only displays
This XML file does not appear to have any style information associated with it. The document tree is shown below.
Blank below

run curl -isS http://.../mycode.cgi, output is
Quote:
HTTP/1.1 200 OK
Date: Thu, 30 Jan 2020 04:07:42 GMT
Server: Apache
Access-Control-Allow-Methods: POST, GET, HEAD, PUT, OPTIONS, PATCH, DELETE
Access-Control-Allow-Origin:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: X-Accept-Charset,X-Accept,Content-Type,X-Requested-With
Connection: close
Transfer-Encoding: chunked
Content-Type: image/svg+xml
The message from /web/logs/error is
Quote:
sh: gnuplot: command not found
[Wed Jan 29 23:12:23.799808 2020] [cgi:error] [pid 160685] AH01215: pclose returned error
I checked the PATH, echo $PATH, it has gnuplot included
Quote:
/opt/python-all/bin:/opt/perl/5.16.3/bin:/opt/fcron/bin:/usr/local/gnuplot/5.0.1/bin:/usr/local/eclipse/4.4.2/bin.....
I tried mycodeurl.cgi
Code:
#!/bin/bash
PATH=$PATH:/usr/local/gnuplot/5.0.1/bin/gnuplot
export PATH
./mycode.cgi
it gave the same message.
 
Old 01-30-2020, 12:21 AM   #32
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,990

Rep: Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441
> I checked the PATH, echo $PATH, it has gnuplot included

It might be set in you login-shell, but it isn't set in the context Apache runs your CGI. Here is how to debug your CGI: https://www.linuxquestions.org/quest...0/#post5707383

Also (as I've already told you) you don't put individual binaries into your PATH, but directories:

before:
Code:
#!/bin/bash
PATH=$PATH:/usr/local/gnuplot/5.0.1/bin/gnuplot
export PATH
./mycode.cgi
after (with some minor changes):
Code:
#!/bin/sh
PATH="$PATH:/usr/local/gnuplot/5.0.1/bin"
export PATH
exec "$(dirname -- "$0")/mycode.cgi"
Of course you don't actually need another file (mycodeurl.cgi), you can set the PATH within your mycode.cgi

Last edited by NevemTeve; 01-30-2020 at 12:40 AM.
 
Old 01-30-2020, 02:33 PM   #33
hpdp
LQ Newbie
 
Registered: Jan 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
@NevemTeve
I checked the link about how to debug CGI, the good news is I can make it work by http://.../mycodeurl.cgi
mycodeurl.cgi
Code:
#!/bin/bash
echo "Content-Type: image/svg+xml"
echo
exec "$(dirname -- "$0")/mycode.cgi"
mycode.cgi
Code:
int main() {
        setenv("PATH", "$PATH:/usr/local/gnuplot/5.0.1/bin", true);
	Gnuplot gp;
        gp << "set term svg\n";	
	gp << "plot sin(x)\n";
}
what I don't understand is, if I put the line Content-Type: image/svg+xml in mycode.C, and call http://.../mycode.cgi directly, it didn't work
Code:
int main() {

	cout<<"Content-Type: image/svg+xml\n\n";
		
	setenv("PATH", "$PATH:/usr/local/gnuplot/5.0.1/bin", true);	
	Gnuplot gp;
        gp << "set term svg\n";	
	gp << "plot sin(x)\n";
}
I checked the /tmp/debug file, the output is
Quote:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg ...>
...
</svg>

Content-Type: image/svg+xml
The Content-Type: image/svg+xml was printed at the bottom, which caused the problem. Thanks a lot!
 
Old 01-30-2020, 03:10 PM   #34
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,990

Rep: Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441Reputation: 1441
You could try to force the data pushed out:
Code:
	cout<<"Content-Type: image/svg+xml\r\n\r\n"<<std::flush;

Last edited by NevemTeve; 01-30-2020 at 03:13 PM.
 
1 members found this post helpful.
Old 01-31-2020, 11:32 AM   #35
hpdp
LQ Newbie
 
Registered: Jan 2016
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
You could try to force the data pushed out:
Code:
	cout<<"Content-Type: image/svg+xml\r\n\r\n"<<std::flush;
That fixed the problem.
Thanks a million!!
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI bash/html/gnuplot : how to generate a graph ? Ezzmazz Programming 2 04-19-2019 10:29 PM
[SOLVED] making a gnuplot 3d graph or gnuplot fence plot Rinndalir Programming 3 10-23-2015 02:10 PM
[SOLVED] gnuplot basic graph problem - noob to gnuplot sudowtf Linux - General 2 04-02-2015 12:00 PM
gnuplot graph using trace file naren123.k Programming 6 11-06-2013 03:42 AM
How to export graph as JPG file in Gnuplot ninja Linux - Software 1 05-30-2003 10:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration