how can let ruby wait until system() return

U

uncutstone

I made use of system() to call a shell script, and found ruby sciprt
run parallelly with the shell script. But I want it wait until system()
return, somebody can help? Thanks in advance.
 
T

ts

u> I made use of system() to call a shell script, and found ruby sciprt
u> run parallelly with the shell script. But I want it wait until system()
u> return, somebody can help? Thanks in advance.

Please give an example because normally ruby wait for #system

moulon% ruby -e 'p Time.now; system("sleep 12"); p Time.now'
Sat Apr 22 14:05:59 CEST 2006
Sat Apr 22 14:06:11 CEST 2006
moulon%
 
U

uncutstone

Yes, you are right. I rethink the problem. It is not caused by ruby
system() call, it seems caused by windows 98 shell command.

FYI.
A simplified example as below:

test.rb:
system("unzip1.bat")
system("unzip2.bat")
system("unzip3.bat")

unzip1.bat:
winrar e -o+ -inul 1.rar

unzip2.bat:
winrar e -o+ -inul 2.rar

unzip3.bat:
winrar e -o+ -inul 3.rar

Then, 3 winrars popup .

Thanks for your kindly help.
 
T

Tim

Yes, you are right. I rethink the problem. It is not caused by ruby
system() call, it seems caused by windows 98 shell command.

FYI.
A simplified example as below:

test.rb:
system("unzip1.bat")
system("unzip2.bat")
system("unzip3.bat")

This occurs because the command shell does not wait on the batch file
to complete before returning I think...

Why not use something like so:

cmd = "winrar e -o+ inul"
system("#{cmd} 1.rar")
system("#{cmd} 2.rar")
system("#{cmd} 3.rar")

In other words, execute the command from the batch file in your ruby
script instead...

HTH,
Tim
 
U

uncutstone

Yes, this example can be modifed as the way you said and it works. But
sometimes you already have some legacy shell script , and you want call
it from ruby. In such situation, the problem remains.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top