Results 1 to 5 of 5

Thread: [C] Need Just a Bit of Help! (System Command)

  1. #1
    Join Date
    Nov 2010
    Location
    Canada
    Beans
    24
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Question [Solved] [C] Need Just a Bit of Help! (System Command)

    Hiya!

    I was programming in C and needed to use some command in the bash shell directly and output in my C command.

    Basically I'm trying to use [ notify-send Test "This is a Test 123." ]
    in my C program using system():
    However it is not working since it is not being executed in the bash shell.
    So how can i run this command from my C program into the bash shell?

    Thanks!
    =D

    Last edited by The Elite Noob; November 22nd, 2010 at 10:55 PM.

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,083
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: [C] Need Just a Bit of Help! (System Command)

    Why do you think that the shell used is the cause of your problem? If that really is what's wrong, then you cannot change the shell that is executed - it will always be /bin/sh. However, if you need bash syntax, then the normal way around this is either to do system("/bin/bash -c 'The Command'") or to place the command in a script and call that from system.

  3. #3
    Join Date
    Nov 2009
    Location
    The Netherlands
    Beans
    239
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: [C] Need Just a Bit of Help! (System Command)

    You could also use a combination of FORK(2) and EXEC(3), that would be a bit more complex, but you have much more control over what happens.
    In combination with PIPE(2) and DUP(2) you could also read the output of the executed command from your program.

    for more info, run `man 2 fork', `man 3 exec' etc. in a terminal

  4. #4
    Join Date
    Nov 2010
    Location
    Canada
    Beans
    24
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [C] Need Just a Bit of Help! (System Command)

    Quote Originally Posted by spjackson View Post
    Why do you think that the shell used is the cause of your problem? If that really is what's wrong, then you cannot change the shell that is executed - it will always be /bin/sh. However, if you need bash syntax, then the normal way around this is either to do system("/bin/bash -c 'The Command'") or to place the command in a script and call that from system.
    Thanks!
    That works Perfectly Thank You Mate!



  5. #5
    Join Date
    Nov 2010
    Beans
    24

    Re: [C] Need Just a Bit of Help! (System Command)

    You can also use the notify library directly:


    #include <libnotify/notification.h>
    #include <libnotify/notify-enum-types.h>
    #include <libnotify/notify.h>

    The functions are:
    notify_notification_new
    notify_notification_show

    Heres some documentation:
    http://www.galago-project.org/docs/a...8h-source.html

Tags for this Thread

Bookmarks

Posting Permissions

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