running system commands with ruby

# notice the backticks
`git config --global user.email`


2 Responses (Add Your Comment)


  1. # notice that you can get the stdout of this command
    # notice that you can check the $? variable for
    # the exist status of your last executed child prozess
    output = `git conifg --global user.email`
    puts "Hooray, it worked out. Lets make snusu." if $?==0


    # notice that you can make your life easier if you
    # just want to fire off a command and forget about stdout
    puts "No Ruby, no snusnu" if system('git config --global user.email')

    And without further ado…
    …some crystal clear internet information: http://whynotwiki.com/Ruby_/_Process_management

    Cheers, Lukas

  2. Hey Lukas,

    Thx a lot for the info! I definitely didn’t know that before, and I must admit this was one of the first snippets i stumbled upon, that deals with system commands! I just had no real need to to do something like that before.

    Many thanks also for the link on ruby process management! Bookmarked that one, I’m sure it will help me some time in the future!

    One more thing. You were the first person ever to comment on my blog! Thx again for sharing your knowledge! I will definitely remember this day :)!

    cheers
    Martin

Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>