470,573 Members | 1,679 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,573 developers. It's quick & easy.

Create new processes over telnet in XP

Hello,

How do you create/spawn new processes in XP over telnet using python?
I.e. I would like to create a new process and have it running in the
background... when I terminate the telnet connection, I would what the
spawned processes to keep running until I shut it off...

I got the os.popen method to spawn a new process running in the
backgroun, but not over telnet... tried os.popen[2, 3, 4] and also
subprocesses.popen without any luck...

Any help will be appreciated... thankyou.

Mar 23 '07 #1
13 3017

Godzilla wrote:
Hello,

How do you create/spawn new processes in XP over telnet using python?
I.e. I would like to create a new process and have it running in the
background... when I terminate the telnet connection, I would what the
spawned processes to keep running until I shut it off...

I got the os.popen method to spawn a new process running in the
backgroun, but not over telnet... tried os.popen[2, 3, 4] and also
subprocesses.popen without any luck...
I don't know what kind of OS there is on that remote host you telnet
to.
The idea boils down to appropriate using of methods
`read_until` and `write` from class `telnetlib.Telnet`.

For more complicated stuff you can consider using pyexpect.

Here is a small example of connecting to HP-UX.
You can adjust that to your needs.

<code>
import telnetlib, time

def login(tn, login, passwd, prompt):
tn.read_until("login: ")
tn.write(login + "\n")
if passwd:
tn.read_until("Password: ")
tn.write(passwd + "\n")
tn.read_until(prompt)
time.sleep(2)
print "logged in"

def run_proc(tn, progname):
tn.write("nohup %s &\n" % progname)
tn.write("exit\n")
print "program <%srunning" % progname

def kill_proc(tn, login, prompt, progname):
tn.write("ps -u %s\n" % login)
buf = tn.read_until(prompt)
pid = get_pid(buf, progname)
if not pid:
print "program <%snot killed" % progname
tn.write("exit\n")
return
tn.write("kill -TERM %s\n" % pid)
tn.write("exit\n")
print "program <%skilled" % progname

def get_pid(buf, progname):
pid, comm = None, None
for line in buf.split("\n"):
try:
pid, _, _, comm = line.split()
except ValueError:
continue
if comm == progname:
return pid

tn = telnetlib.Telnet(HOST, PORT)
#tn.set_debuglevel(1)
login(tn, "login", "passwd", "/home/user")
run_proc(tn, "python ~/test.py")
#kill_proc(tn, "login", "/home/user", "python")
</code>

--
HTH,
Rob

Mar 23 '07 #2
On 23 Mar 2007 03:47:14 -0700, Godzilla <go***********@gmail.comwrote:
Hello,

How do you create/spawn new processes in XP over telnet using python?
I.e. I would like to create a new process and have it running in the
background...
Ssh -- or even rsh -- are better choices than telnet for these things.
For some reason, they are not standard in Windows, though.

ssh somewhere some command with arguments
rsh somewhere some command with arguments

compared to

telnet somewhere

and then performing expect-like things (basically simulating
someone typing "some command with arguments" in the telnet
session).
when I terminate the telnet connection, I would what the
spawned processes to keep running until I shut it off...
That's a function of the remote OS; what happens when its terminal
goes away is not under the control of the client side.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org R'lyeh wgah'nagl fhtagn!
Mar 23 '07 #3
Jorgen Grahn wrote:
On 23 Mar 2007 03:47:14 -0700, Godzilla <go***********@gmail.comwrote:
>Hello,

How do you create/spawn new processes in XP over telnet using python?
I.e. I would like to create a new process and have it running in the
background...

Ssh -- or even rsh -- are better choices than telnet for these things.
For some reason, they are not standard in Windows, though.

ssh somewhere some command with arguments
rsh somewhere some command with arguments

compared to

telnet somewhere

and then performing expect-like things (basically simulating
someone typing "some command with arguments" in the telnet
session).
+ for an sshd running as a service under XP, look at CopSSH.

+ hope started process doesn't want a GUI... else, look at UltraVNC running
as daemon, and port redirection using ssh.
>
>when I terminate the telnet connection, I would what the
spawned processes to keep running until I shut it off...

That's a function of the remote OS; what happens when its terminal
goes away is not under the control of the client side.
Maybe the process starting job can be done by a Python program running as
Windows service and waiting for requests on a port (or Pyro object or Corba
object...).
No need for telnet/ssh connection, no logout problem.

Just care of possible security problems :-)

Mar 23 '07 #4
This reminds me of something I once wanted to do: How can I install
Python in a totally non-gui way on Windows (without the use of VNC)? I
think I was telnetted into a computer (or something like that) and I was
unable to run the usual Python installer because it uses a GUI.

Laurent Pointal wrote:
Jorgen Grahn wrote:

>On 23 Mar 2007 03:47:14 -0700, Godzilla <go***********@gmail.comwrote:
>>Hello,

How do you create/spawn new processes in XP over telnet using python?
I.e. I would like to create a new process and have it running in the
background...
Ssh -- or even rsh -- are better choices than telnet for these things.
For some reason, they are not standard in Windows, though.

ssh somewhere some command with arguments
rsh somewhere some command with arguments

compared to

telnet somewhere

and then performing expect-like things (basically simulating
someone typing "some command with arguments" in the telnet
session).

+ for an sshd running as a service under XP, look at CopSSH.

+ hope started process doesn't want a GUI... else, look at UltraVNC running
as daemon, and port redirection using ssh.

>>when I terminate the telnet connection, I would what the
spawned processes to keep running until I shut it off...
That's a function of the remote OS; what happens when its terminal
goes away is not under the control of the client side.

Maybe the process starting job can be done by a Python program running as
Windows service and waiting for requests on a port (or Pyro object or Corba
object...).
No need for telnet/ssh connection, no logout problem.

Just care of possible security problems :-)

--
Shane Geiger
IT Director
National Council on Economic Education
sg*****@ncee.net | 402-438-8958 | http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy
Mar 23 '07 #5
Shane Geiger wrote:
This reminds me of something I once wanted to do: How can I install
Python in a totally non-gui way on Windows (without the use of VNC)? I
think I was telnetted into a computer (or something like that) and I was
unable to run the usual Python installer because it uses a GUI.
Python uses a MSI (microsoft installer) based installer on windows.
This was introduced in version 2.5 I believe.

For MSI installers there's the standard MSI-way to perform a "silent" install.
Google for it, I don't know what the command line switch(es) are, but they're there.

--Irmen

Mar 23 '07 #6
Irmen de Jong napisa³(a):
Python uses a MSI (microsoft installer) based installer on windows.
This was introduced in version 2.5 I believe.
2.4? I recall that we installed 2.4.2 this way on >500 machines some day
at my previous work.

--
Jarek Zgoda
http://jpa.berlios.de/
Mar 23 '07 #7
On Mar 24, 12:57 am, "Rob Wolfe" <r...@smsnet.plwrote:
Godzilla wrote:
Hello,
How do you create/spawn new processes in XP over telnet using python?
I.e. I would like to create a new process and have it running in the
background... when I terminate the telnet connection, I would what the
spawned processes to keep running until I shut it off...
I got the os.popen method to spawn a new process running in the
backgroun, but not over telnet... tried os.popen[2, 3, 4] and also
subprocesses.popen without any luck...

I don't know what kind of OS there is on that remote host you telnet
to.
The idea boils down to appropriate using of methods
`read_until` and `write` from class `telnetlib.Telnet`.

For more complicated stuff you can consider using pyexpect.

Here is a small example of connecting to HP-UX.
You can adjust that to your needs.

<code>
import telnetlib, time

def login(tn, login, passwd, prompt):
tn.read_until("login: ")
tn.write(login + "\n")
if passwd:
tn.read_until("Password: ")
tn.write(passwd + "\n")
tn.read_until(prompt)
time.sleep(2)
print "logged in"

def run_proc(tn, progname):
tn.write("nohup %s &\n" % progname)
tn.write("exit\n")
print "program <%srunning" % progname

def kill_proc(tn, login, prompt, progname):
tn.write("ps -u %s\n" % login)
buf = tn.read_until(prompt)
pid = get_pid(buf, progname)
if not pid:
print "program <%snot killed" % progname
tn.write("exit\n")
return
tn.write("kill -TERM %s\n" % pid)
tn.write("exit\n")
print "program <%skilled" % progname

def get_pid(buf, progname):
pid, comm = None, None
for line in buf.split("\n"):
try:
pid, _, _, comm = line.split()
except ValueError:
continue
if comm == progname:
return pid

tn = telnetlib.Telnet(HOST, PORT)
#tn.set_debuglevel(1)
login(tn, "login", "passwd", "/home/user")
run_proc(tn, "python ~/test.py")
#kill_proc(tn, "login", "/home/user", "python")
</code>

--
HTH,
Rob
Thanks guys for your input...

Rob, I will give your example a go soon and tell you how i go...

Have a nice day...

Mar 24 '07 #8
On Mar 24, 12:57 am, "Rob Wolfe" <r...@smsnet.plwrote:
Godzilla wrote:
Hello,
How do you create/spawn new processes in XP over telnet using python?
I.e. I would like to create a new process and have it running in the
background... when I terminate the telnet connection, I would what the
spawned processes to keep running until I shut it off...
I got the os.popen method to spawn a new process running in the
backgroun, but not over telnet... tried os.popen[2, 3, 4] and also
subprocesses.popen without any luck...

I don't know what kind of OS there is on that remote host you telnet
to.
The idea boils down to appropriate using of methods
`read_until` and `write` from class `telnetlib.Telnet`.

For more complicated stuff you can consider using pyexpect.

Here is a small example of connecting to HP-UX.
You can adjust that to your needs.

<code>
import telnetlib, time

def login(tn, login, passwd, prompt):
tn.read_until("login: ")
tn.write(login + "\n")
if passwd:
tn.read_until("Password: ")
tn.write(passwd + "\n")
tn.read_until(prompt)
time.sleep(2)
print "logged in"

def run_proc(tn, progname):
tn.write("nohup %s &\n" % progname)
tn.write("exit\n")
print "program <%srunning" % progname

def kill_proc(tn, login, prompt, progname):
tn.write("ps -u %s\n" % login)
buf = tn.read_until(prompt)
pid = get_pid(buf, progname)
if not pid:
print "program <%snot killed" % progname
tn.write("exit\n")
return
tn.write("kill -TERM %s\n" % pid)
tn.write("exit\n")
print "program <%skilled" % progname

def get_pid(buf, progname):
pid, comm = None, None
for line in buf.split("\n"):
try:
pid, _, _, comm = line.split()
except ValueError:
continue
if comm == progname:
return pid

tn = telnetlib.Telnet(HOST, PORT)
#tn.set_debuglevel(1)
login(tn, "login", "passwd", "/home/user")
run_proc(tn, "python ~/test.py")
#kill_proc(tn, "login", "/home/user", "python")
</code>

--
HTH,
Rob
Rob, I would be logging into another XP machine to do some software
installation... the code you provided, correct me if I'm wrong, seems
to work under Unix/Linux. Any idea how to do the equivalent in XP?

Mar 24 '07 #9
Irmen de Jong schrieb:
Shane Geiger wrote:
>This reminds me of something I once wanted to do: How can I install
Python in a totally non-gui way on Windows (without the use of VNC)? I
think I was telnetted into a computer (or something like that) and I was
unable to run the usual Python installer because it uses a GUI.

Python uses a MSI (microsoft installer) based installer on windows.
This was introduced in version 2.5 I believe.

For MSI installers there's the standard MSI-way to perform a "silent" install.
Google for it, I don't know what the command line switch(es) are, but they're there.

--Irmen
Even the Wise installer that was used to build the 2.3 and earlier versions
had command line switches to do silent installs.

THomas

Mar 24 '07 #10
"Godzilla" <go***********@gmail.comwrites:
Rob, I would be logging into another XP machine to do some software
I was afraid of that. :)
installation... the code you provided, correct me if I'm wrong, seems
to work under Unix/Linux.
This part of running and killing processes, yes.
Any idea how to do the equivalent in XP?
You could use windows services, for example:
http://aspn.activestate.com/ASPN/Coo.../Recipe/115875

But I don't know details, because this is not my favourite OS. :)

--
Regards,
Rob
Mar 24 '07 #11
Shane Geiger a écrit :
This reminds me of something I once wanted to do: How can I install
Python in a totally non-gui way on Windows (without the use of VNC)? I
think I was telnetted into a computer (or something like that) and I was
unable to run the usual Python installer because it uses a GUI.
Take a look at PortablePython, this may be the easy solution...

http://www.portablepython.com/
A+

Laurent.

Mar 26 '07 #12
Laurent Pointal wrote:
Shane Geiger a écrit :
>This reminds me of something I once wanted to do: How can I install
Python in a totally non-gui way on Windows (without the use of VNC)? I
think I was telnetted into a computer (or something like that) and I was
unable to run the usual Python installer because it uses a GUI.
While I don't remember if I've actually tried it you should
be able to do this with WMI. Example here...

http://timgolden.me.uk/python/wmi_co...tall-a-product

If I have time to do it (and then undo whatever damage it
does ;) I'll give it a go later.

TJG
Mar 26 '07 #13
Tim Golden wrote:
Laurent Pointal wrote:
>Shane Geiger a écrit :
>>This reminds me of something I once wanted to do: How can I install
Python in a totally non-gui way on Windows (without the use of VNC)? I
think I was telnetted into a computer (or something like that) and I was
unable to run the usual Python installer because it uses a GUI.

While I don't remember if I've actually tried it you should
be able to do this with WMI. Example here...

http://timgolden.me.uk/python/wmi_co...tall-a-product

If I have time to do it (and then undo whatever damage it
does ;) I'll give it a go later.

TJG
Or, indeed, just run it in quiet mode, according to the docs:

http://www.python.org/download/releases/2.5/msi/

TJG
Mar 26 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Guy | last post: by
3 posts views Thread by Yannick Turgeon | last post: by
4 posts views Thread by Donnal Walter | last post: by
2 posts views Thread by john brown | last post: by
2 posts views Thread by eight02645999 | last post: by
17 posts views Thread by ravimath | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.