Hi

Johan Geldenhuys wrote:
> Hugo,
> 
> I see that 'os.execcvp()' doesn't actually make two seperate processes. 
> This is what I have working now:
> """
> 
> import os, signal, time
> pid = os.fork()
> print 'pid; ',pid
> if pid == 0: #child process
>            #os.execvp('tcpdump', ['tcpdump', '-i modem0 > cap1.txt'])
>       os.execvp('ping', ['ping', '127.0.0.1 -c 30 > cap.txt'])

The following line (sleep)is superluous, as  it is no longer your python
script after calling exec()
Your process (in this case the child process)is replaced with  a copy of
ping in memory.

>      time.sleep(5)
> kill(pid)
> 
> def kill(pid, signal=signal.SIGTERM):
>    print "trying to kill pid...", pid
>    os.kill(pid, signal)
>    os.waitpid(pid, 0)
>    print "Killed %d"%pid
> """
> 
> The ping command is executed but the part where it must put the replies 
> in the file is not recognized. How do I use the addisional arguments to 
> be seen?
> 

Mmm no, this line:

>       os.execvp('ping', ['ping', '127.0.0.1 -c 30 > cap.txt'])

uses *shell redirection*.. guess who has to interpret the whole > thing..

As you are using no shell, the '>' argument is passed to the ping
program, which knows nothing of handling it the way you expect it.

What you're doing is equivalent to (in my workstation)

[EMAIL PROTECTED]:~# ping  192.168.0.8  ">" cap.txt
ping: unknown host >

You have to call a shell if you want to use redirection, otherwise you
will have to use python to send all of ping's output to a file (which
would be a nice exercise, IMHO ;) )

Hugo
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to