Execute Shell-Script in the background



  • hey guys..

    i wanna start the text.cgi within the php document by a button.. this works fine

    <form action="cgi-bin/text.cgi">
    <input type="submit" value="hit me">
    </form>

    -----------------------------------------------------

    in the cgi-file i want to execute some shell commands.. the problem of the start.sh is, that the process runs in the front and i dont arrive the "return(0)" command.. i wanna reach, that i close the cgi script after starting the shell script and go further on the php site..(running the shell-file in the background didn't help yet -

    thanks in advance for some help 🙂

    int main(void)
    {
    printf("Content-Type: text/html; charset=iso-8859-1\n\n");
    system("rm -r /mjpg-streamer/pics/* && /mjpg-streamer/start.sh");
    return 0;
    }

    mfg mlgRs


  • Mod

    Your webserver calls a CGI-File which calls a binary executable that calls a shell that calls a shell script that calls the actual commands? 😮 I do not know much about web development but that sounds awfully convoluted. Maybe you should ask for a better solution in the "Webzeugs"-forum. BTW: If you have problems with English language you could try another language, maybe you are lucky and someone else in this forums speaks your language.

    Concerning your question: It sounds like you want to use fork and exec instead of system. You can also exec a shell if you really need the shell that a system-command would spawn (hint: you probably do not need it).
    But:
    Please look for another solution. As I explained above it sounds as if you are constructing your very own Rube Goldberg machine for creation of web content.



  • i wrote the thread really fast.. maybe because of that the english wasn't the best.. sry :p

    i'm going to make a website for webcam configuration.. the webcam is installed on a linux based foxboard and so i have to start it with shell commands.. that's the reason for the many detours!

    but thanks for your fast reply.. i will try the fork() command to solve the problem


  • Mod

    mlgRs schrieb:

    but thanks for your fast reply.. i will try the fork() command to solve the problem

    No! You should try to get rid of all those detours first! I do not know the solution because I don't do web development, but I am sure there must be a much better way to do this.


Anmelden zum Antworten