Python - forking an external process?

V

Victor Hooi

Hi,

I have a Python script where I want to run fork and run an external command (or set of commands).

For example, after doing <xyz>, I then want to run ssh to a host, handover control back to the user, and have my script terminate.

Or I might want to run ssh to a host, less a certain textfile, then exit.

What's the idiomatic way of doing this within Python? Is it possible to do with Subprocess?

Cheers,
Victor

(I did see this SO post - http://stackoverflow.com/questions/...-it-continue-to-run-after-the-script-is-kille, but it's a bit older, and I was going to see what the current idiomatic way of doing this is).
 
R

rusi

Hi,

I have a Python script where I want to run fork and run an external command
(or set of commands).
For example, after doing <xyz>, I then want to run ssh to a host, handover
control back to the user, and have my script terminate.

Seen Fabric?
http://docs.fabfile.org/en/1.6/

Recently -- within the last month methinks -- there was someone who posted a supposed improvement to it (forget the name)
 
V

Victor Hooi

Hi,

Hmm, this script is actually written using the Cliff framework (https://github.com/dreamhost/cliff).

I was hoping to keep the whole approach fairly simple, without needing to pull in too much external stuff, or set anything up.

There's no way to do it with just Python core is there?

Also, what's this improvement you mentioned?

Cheers,
Victor
 
R

Roy Smith

Victor Hooi said:
Hi,

I have a Python script where I want to run fork and run an external command
(or set of commands).

For example, after doing <xyz>, I then want to run ssh to a host, handover
control back to the user, and have my script terminate.

Or I might want to run ssh to a host, less a certain textfile, then exit.

What's the idiomatic way of doing this within Python? Is it possible to do
with Subprocess?

I suspect you are trying to reinvent fabric. It is designed to do
exactly these things (in particular, handling all the really complicated
stuff about ssh).

See http://docs.fabfile.org/
 
A

Antoon Pardon

Op 03-07-13 05:47, Victor Hooi schreef:
Hi,

I have a Python script where I want to run fork and run an external command (or set of commands).

For example, after doing <xyz>, I then want to run ssh to a host, handover control back to the user, and have my script terminate.

Or I might want to run ssh to a host, less a certain textfile, then exit.

What's the idiomatic way of doing this within Python? Is it possible to do with Subprocess?

If I understand correctly that you want something done in python and then wish to finish
python and give control to an other program. I would use an external script that would
first launch the python program and then the other program.

If for some reason this is a less attractive option, you can use the os.exec family.
That terminates the python program will starting up an other program.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top