starting a process after the previous one is done

P

Partha

I am a RUBY NUBY.

Was trying to use ruby to automate a set of tasks.
In trying to do so I need process2 to start only after process1 is
done.
I am using a code similar to below, but does not seem to work.

I want the process 1f_after to execute after the exec command is done.
So I would expect that the time stamp of "1f_after" is later than the
time stamp of "1f" but does not happen so.

How could I do this?
(process2 & process1 are not necessarily system commands I am trying to
executea part of a cad tool in process1 & 2)

Thankyou,
Partha



#!/usr/local/bin/ruby -W

print "Start\n"
exec("ls -lrt /home/xyz > 1f") if fork == nil
Process.wait
system("touch 1f_after")
 
C

Corey Jewett

I'm a complete noob too, but can't you just:

#!/usr/local/bin/ruby -W

print "Start\n"
system("ls -lrt /home/xyz > 1f")
system("touch 1f_after")

Corey
 
P

Partha

Corey,
When I do so, it does the same thing
I dont think ruby waits for the previous system command to be done
before it runs the next line.
( They are concurrent?)

Ay other ideas of how I would be abel to wait on the previous process
to run the next one?

Snippet shown below.

Thankyou,
Partha


-rw-rw-r-- 1 pvn cad 0 Oct 17 10:27 1f_after
-rw-rw-r-- 1 pvn cad 61261 Oct 17 10:27 1f

pvngemini/home/pvn >cat t.rb
#!/usr/local/bin/ruby -W

print "Start\n"
system("ls -lrt /home/pvn > 1f")
system("touch 1f_after")


pvngemini/home/pvn >
 
R

Robert Klemme

Partha said:
Corey,
When I do so, it does the same thing
I dont think ruby waits for the previous system command to be done
before it runs the next line.
( They are concurrent?)

No way: sytem is synchronous, i.e. ruby will block until it has finished.
Try it:

$ ruby -e 'system("sleep 10; echo 1");system("echo 2")'
1
2
Ay other ideas of how I would be abel to wait on the previous process
to run the next one?

If you see something different then maybe the processes you start are
forking. For some programs usually started as daemon there's a flag that
prevents running in the background. Maybe that can help you.

Other than that, if your programms fork themselfes you need to find a way to
determine execution state and wait to that status change.
Snippet shown below.

What exactly do you want to demonstrate with this?
-rw-rw-r-- 1 pvn cad 0 Oct 17 10:27 1f_after
-rw-rw-r-- 1 pvn cad 61261 Oct 17 10:27 1f

pvngemini/home/pvn >cat t.rb
#!/usr/local/bin/ruby -W

print "Start\n"
system("ls -lrt /home/pvn > 1f")
system("touch 1f_after")

You can't really expect timestamps with differnt minutes, can you? If you
have GNU ls you can use option --full-time:

Robert@Babelfish2 /c/TEMP
$ touch 1 ; touch 2

Robert@Babelfish2 /c/TEMP
$ ls -t --full-time 1 2
-rw-r--r-- 1 Robert Kein 0 2005-10-17 20:55:30.234375000 +0200 2
-rw-r--r-- 1 Robert Kein 0 2005-10-17 20:55:30.140625000 +0200 1

Robert@Babelfish2 /c/TEMP

Kind regards

robert
 

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
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top