473,378 Members | 1,280 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 3119

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dan | last post by:
I'm writing a simplistic telnet client in VB6 and I've run into a small snag. The program has a textbox to write in the string to be sent using ..SendData and has another textbox that displays...
1
by: Guy | last post by:
Hi I've done some projects in python for my work which invole some test scripts etc. All quite basic stuff, I find python a good language to work in but have come up against a brick wall. I'm...
3
by: Yannick Turgeon | last post by:
Hello all, I'm currently trying to pass commands to a telnet session and get the texte generated (stdin + stdout) by the session. The problem I get is that the Telnet.read_until() function...
4
by: Donnal Walter | last post by:
On Windows XP I am able to connect to a remote telnet server from the command prompt using: telnet nnn.nnn.nnn.nnn 23 where nnn.nnn.nnn.nnn is the IP address of the host. But using telnetlib,...
2
by: john brown | last post by:
I'm telnetting into a router. Apart from the fact I can't seem to view the output when iniciating the session, I can't match one of the expressions using Net::Telnet. I can telnet into the router...
3
by: Wizou | last post by:
i'm using .NET 2.0, and i've made a lot of tests i've come to the conclusion that TCP servers (tcplistener), started by a father process, are somewhat inherited by child processes if using...
2
by: eight02645999 | last post by:
hi i am using a telnet session to simulate an authentication mechanism USER = "user" PASSWORD = "password" try: telnet = telnetlib.Telnet(HOST) telnet.set_debuglevel(5)...
2
by: thilandeneth | last post by:
i need to do telnet via a web server please give me a idia to initiate the project following requirements are needed 1 Create web based custom telnet client to communicate with remote...
17
by: ravimath | last post by:
Dear all, I have written following script to loin to router bu it is showing error. #!c:\Perl\bin; use strict; use warnings; my $hostname = 'REMOVED FOR YOUR PROTECTION'; my $password =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.