System Commands for UNIX

This is a discussion on System Commands for UNIX within the C Programming forums, part of the General Programming Boards category; At a certain point in my c code I want to run a program in the same directory. Then immediately ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    115

    System Commands for UNIX

    At a certain point in my c code I want to run a program in the same directory. Then immediately return control back to code. What command and paramaters do I need to use? Thanks.

    -Carl

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Do you mean that you want to run the application in the background?

    If so, just compile the code normally, and add "&" to the back of the command, e.g.:
    Code:
    $ myprog &
    That will run myprog as a background task, and as long as myprog doesn't require input from the stdin stream, that should be fine.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    115

    Yes In The Backround

    In my c code how do I force another program in the same directory as my code to run before I continue. I need another file to update (which executing the program does) so the data my current code will work on is up to date. I hope that makes sense. Thanks.

    -Carl

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by cjohnman View Post
    In my c code how do I force another program in the same directory as my code to run before I continue. I need another file to update (which executing the program does) so the data my current code will work on is up to date. I hope that makes sense. Thanks.

    -Carl
    Code:
    system("/some/prog/to/run");
    The tricky part is finding the directory where your program is stored. This is not as simple as it sounds.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Generally, I would use a shell-script, something where you just "list" the commands you need to execute, e.g.
    Code:
    #!/bin/sh    # This is a "magic" for "This is a shell-script". 
    prog1          # first program to run
    prog2          # second program to run.
    It's much more easy (and easier to change later) to use a shell-script than to write C code to do the same work.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    115

    Thumbs up That works great - Thanks!

    Thanks for your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. running system commands??
    By killdragon in forum C++ Programming
    Replies: 13
    Last Post: 09-25-2004, 02:49 PM
  2. what can i type into msdn to bring up all the system commands
    By Shadow12345 in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2002, 05:58 PM
  3. Capturing system commands
    By manwhoonlyeats in forum C Programming
    Replies: 2
    Last Post: 12-07-2002, 06:38 PM
  4. System(); commands
    By Ryan in forum C++ Programming
    Replies: 15
    Last Post: 03-15-2002, 06:05 PM
  5. system commands
    By mervin in forum C Programming
    Replies: 3
    Last Post: 02-03-2002, 08:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21