How to not display output of a system call

Lets say I have a Windows command line program that runs the following:

system(“del *.txt”)

How do I NOT display the output from the del command?

Thank you.

Also, how do you make the program pause for a few seconds.

On 10/06/2009 10:45 PM, Jerry Mr wrote:

Also, how do you make the program pause for a few seconds.

Put it to SLEEP.

robert

On 10/06/2009 10:29 PM, Jerry Mr wrote:

Lets say I have a Windows command line program that runs the following:

system(“del *.txt”)

How do I NOT display the output from the del command?

Thank you.

In this case:

Dir["*.txt"].each {|f| File.delete f}

:slight_smile:

robert

Jerry Mr wrote:

Also, how do you make the program pause for a few seconds.

$ ri Kernel#sleep
----------------------------------------------------------- Kernel#sleep
sleep([duration]) => fixnum

  From Ruby 1.9.1

  Suspends the current thread for duration seconds (which may be any
  number, including a Float with fractional seconds). Returns the
  actual number of seconds slept (rounded), which may be less than
  that asked for if another thread calls Thread#run. Zero arguments
  causes sleep to sleep forever.

     Time.new    #=> 2008-03-08 19:56:19 +0900
     sleep 1.2   #=> 1
     Time.new    #=> 2008-03-08 19:56:20 +0900
     sleep 1.9   #=> 2
     Time.new    #=> 2008-03-08 19:56:22 +0900

Jerry Mr wrote:

Lets say I have a Windows command line program that runs the following:

system(“del *.txt”)

How do I NOT display the output from the del command?

Thank you.

del *.txt

That’s backticks, not apostrophes. Also, this won’t prevent the display
of output to stderr, only stdout.

Tim H. wrote:

del *.txt

That’s backticks, not apostrophes. Also, this won’t prevent the display
of output to stderr, only stdout.

Hrmm, backticks don’t seem to work on windows boxes.

Tries to point to a CMD variable instead.

@Robert K.

I agree that doing it entirely in ruby would be the better way to go
about it.
Just sometimes it is quicker to use a command that is already available
(or run a utility I added to %path%) to speed things up at work.

Plus, now that I am wondering, it will haunt me until I find the answer.

Jerry Piazza wrote:

I am now trying to impliment this.

I created this:
def spinner spin_trigger
while (spin_trigger == true)
print “\\r”
sleep 1
print “|\r”
sleep 1
print “/\r”
sleep 1
print “-\r”
sleep 1
end
end

spin = true
Thread.new do
spinner spin
end
files = Dir.glob(“c:/**/*.txt”)
spin = false

But all I get is a “” stuck at the beginning of the line until the Dir
command finishes.

Maybe I am confused about the usage of Thread?

I think you have some more basic issues to deal with first. What do you
think the output of the following code will be:

def test(x)
while x == 20
sleep 3
puts x
end
end

x = 10
test(20)
x = 30

I am now trying to impliment this.

I created this:
def spinner spin_trigger
while (spin_trigger == true)
print “\\r”
sleep 1
print “|\r”
sleep 1
print “/\r”
sleep 1
print “-\r”
sleep 1
end
end

spin = true
Thread.new do
spinner spin
end
files = Dir.glob(“c:/**/*.txt”)
spin = false

But all I get is a “” stuck at the beginning of the line until the Dir
command finishes.

Maybe I am confused about the usage of Thread?

Jerry Piazza wrote:

Lets say I have a Windows command line program that runs the following:

system(“del *.txt”)

How do I NOT display the output from the del command?

You could try something like this:

system(“del *.txt >NUL”)

Otherwise try IO.popen, which can capture the output of the command, so
you can throw it away.

On 07.10.2009 04:58, 7stud – wrote:

Jerry Piazza wrote:

I am now trying to impliment this.

I created this:
def spinner spin_trigger
while (spin_trigger == true)

Comparing with “true” or “false” to obtain a boolean value is a very bad
idea - especially in Ruby which has two false values and unlimited true
values.

Maybe I am confused about the usage of Thread?

x = 10
test(20)
x = 30

Absolutely!

robert