0

I'm trying to make a small project with a server and a Raspberry Pi. I have almost everything done, the only thing I need is the following one:

I have a C program which works perfect with my raspberry if a call it from command line but I want it to be run when a button is clicked in my server.

So my question is, how can I run the C program from inside the CGI?

I was trying this INSIDE THE CGI FILE but with no succeed:

#!/bin/bash
./myCompiledCprogram
Taylan Aydinli
  • 4,333
  • 15
  • 39
  • 33
Aldridge1991
  • 1,326
  • 6
  • 24
  • 51
  • 1
    "No success" is a very bad description of the problem. Please state more clearly what phenomenon you observe and what you want instead. – Alfe Dec 10 '13 at 11:07
  • Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. – Aldridge1991 Dec 10 '13 at 11:08
  • Have a look at the log files of the web server. They should be more descriptive. Their location probably can be found in the web server's configuration or documentation. – Alfe Dec 10 '13 at 11:09
  • [Tue Dec 10 11:17:57 2013] [error] [client 172.17.223.62] Premature end of script headers: set01.cgi, referer: http://172.17.226.58/ – Aldridge1991 Dec 10 '13 at 11:20
  • 1
    Maybe this helps: http://stackoverflow.com/questions/17583341/error-500-premature-end-of-script-headers – Alfe Dec 10 '13 at 11:22
  • In fact, what I want to do is to execute a C script when a button in the server is clicked. I'm not sure if this is the best way. Any idea? – Aldridge1991 Dec 10 '13 at 11:30
  • 1
    Specify the full path name to the C program, rather than relative. The current directory might not be the same as the directory where the CGI file resides. – cdarke Dec 10 '13 at 12:08
  • 2
    At the top of the `main()` function in your C file, add the line `printf("Content-Type: text/html\r\n\r\n");` (or `text/plain`, perhaps? What sort of output does your code produce?). You can then put the compiled file in your /cgi-bin folder and access it directly with your browser. The convention is to give the compiled file a `.cgi` extension at the end of its filename, although this isn't mandatory. @Alfe has linked to a page with plenty more information. – r3mainer Dec 10 '13 at 12:26

0 Answers0