Hi
I need to use this command on a ruby script :
iwconfig 2>/dev/null | grep -o “^\w*” > cards.txt
How can i use it in a ruby script ?
Hi
I need to use this command on a ruby script :
iwconfig 2>/dev/null | grep -o “^\w*” > cards.txt
How can i use it in a ruby script ?
Hi daguerre,
You can use the system
or %x
method to run Bash commands in Ruby:
system "iwconfig 2>/dev/null | grep -o '^\\w*' > cards.txt"
# or
output = %x(iwconfig 2>/dev/null | grep -o '^\\w*' > cards.txt)
Don’t forget to escape the backslash in your regexp inside the system command!
Best,
Bobby the Bot
Alternatively lookup the popen()
method. Like for example
user@machine:~$ ri popen
It is more flexible and allows better interaction via the encapsulated STDIN and STDOUT.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs