Find the answer to your Linux question:
Results 1 to 9 of 9
Hi guys, I would like to execute an already written C program that I am running on my embedded Linux, but from afar - through a HTML page. I am ...
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    2

    Execute C program through a HTML on a http web server - embeded Linux

    Hi guys,

    I would like to execute an already written C program that I am running on my embedded Linux, but from afar - through a HTML page.

    I am running an embedded Linux on my FPGA prototype board with a MicroBlaze soft processor. On this Linux i am running a httpd web server - I can serve html web pages to the outside through Ethernet connection.
    Now, I have a program written in C in this embedded Linux in /bin/gpio-test that does some stuff with my IO devices.
    Now I would like to control these IO devices through HTML web page - so I would like to be able to run this gpio-test program from a html web page and possibly send the program some parameters.

    Can you help?

    Thanks a lot!

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Look for CGI (common gateway interface).
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined!
    Join Date
    Jun 2010
    Posts
    2
    I did.

    I put a simple hello.c in my CGI-BIN folder for embedded system, where I have access via HTTP:

    #include <stdio.h>
    int main(void) {
    printf("Content-Type: text/plain;charset=us-ascii\n\n");
    printf("Hello world\n\n");
    return 0;
    }

    Then I did gcc -o hello.cgi hello.c
    Then I built the embedded system (cross-compiled on my host machine - mb-linux-gcc) and transferred the image to the system.

    When I run ./hello.cgi locally on the embedded system I get:
    ./hello.cgi: 1: Syntax error: "(" unexpected

    So it doesn't even work locally.

  4. #4
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    Okay, so what is the nature of the embedded system? Are you sure you have the correct cross toolchain to build binaries for that architecture? Have you run cross-compiled code on the embedded system before?
    --- rod.
    Stuff happens. Then stays happened.

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Also, how did you transfer the file to the embedded system? If you used FTP, the .cgi extension may have been misinterpreted as a text file and it may have converted some of the embedded characters during the transfer.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Just Joined! sixdrift's Avatar
    Join Date
    Jan 2007
    Location
    In and around and about Cary, NC
    Posts
    44
    Another piece of information that would help is what httpd server are you using. You need to ensure the CGI connection is configured correctly for the server.

  7. #7
    Linux Newbie
    Join Date
    Mar 2010
    Posts
    121
    At work, we use haserl (haserl.sourceforge.net) running on lighttpd, which I don't really know how to use (I just compile it and make it available to more web-oriented people ) and I don't know how it compares to CGI, but I think it's basically like being able to put bash scripting in HTML, and the people who use it here seem to like it.

  8. #8
    Just Joined! sixdrift's Avatar
    Join Date
    Jan 2007
    Location
    In and around and about Cary, NC
    Posts
    44
    In relooking at the original error message in the OP, I think the problem is with the shell on the embedded system trying to run the hello.cgi as an interpreted script with some interpreter. There may be further HTTP server config needed as well.

    Just for grins, can you drop the .cgi extension and does it work right on the target system?

  9. #9
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    Quote Originally Posted by sixdrift View Post
    In relooking at the original error message in the OP, I think the problem is with the shell on the embedded system trying to run the hello.cgi as an interpreted script with some interpreter. There may be further HTTP server config needed as well.

    Just for grins, can you drop the .cgi extension and does it work right on the target system?
    You could be right. My thought was that the error message looks like he tried to run the C source code in a shell. The #include first line looks like a comment, and the first thing to be syntactically wrong is the opening parenthesis, which is what the error message contains.
    It looks like the OP is doing a hit & run, so I've quit losing sleep over this one.
    --- rod.
    Stuff happens. Then stays happened.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...