Find the answer to your Linux question:
Results 1 to 3 of 3

Thread: C: system()

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    C: system()

    How can I execute several commands in one system() call?

    For example: system("echo -n 'hey'; ls -l /tmp; echo -n 'bye'");

    I tried ";", " ", "," and "|" but it always prints the whole string.

  2. #2
    Doesn't && do it for you?

  3. #3
    Linux Guru
    Join Date
    Oct 2001
    Täby, Sweden
    I'm not sure that I understand your problem. When I compile that exact line that you gave and run the resulting program, I get "hey", followed by a listing of /tmp, followed by "bye". Is that not what you want?

    #include <stdlib.h>
    #include <unistd.h>
    #include <stdio.h>
    int main(void)
        system("echo -n 'hey'; ls -l /tmp; echo -n 'bye'");

  4. $spacer_open

Posting Permissions

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