Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to not display output of a system call.

Reply
Thread Tools

How to not display output of a system call.

 
 
Jerry Mr
Guest
Posts: n/a
 
      10-06-2009
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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Jerry Mr
Guest
Posts: n/a
 
      10-06-2009
Also, how do you make the program pause for a few seconds.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      10-06-2009
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}



robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      10-06-2009
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

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
Tim Hunter
Guest
Posts: n/a
 
      10-06-2009
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.

--
RMagick is looking for a maintainer. Email me if you're interested.

 
Reply With Quote
 
Tim Hunter
Guest
Posts: n/a
 
      10-06-2009
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


--
RMagick is looking for a maintainer. Email me if you're interested.

 
Reply With Quote
 
Jerry Piazza
Guest
Posts: n/a
 
      10-06-2009
Tim Hunter 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 Klemme

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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Jerry Piazza
Guest
Posts: n/a
 
      10-07-2009
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?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
7stud --
Guest
Posts: n/a
 
      10-07-2009
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

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      10-07-2009
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.

>> 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


Absolutely!

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Not able to display color in excel not able to display color in excel using xml sed_y XML 0 02-15-2012 09:46 PM
FreeRIDE is not displaying the output in the output window juhunu@gmail.com Ruby 1 05-23-2006 01:08 PM
choosing to display or not to display a checkbox in repeater control. Imran Aziz ASP .Net 4 08-11-2005 05:00 PM
System.Security.SecurityException: Error de solicitud de permiso de tipo System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. Luis Esteban Valencia ASP .Net 0 07-14-2005 01:43 PM



Advertisments