在XP中通过telnet创建新进程 [英] Create new processes over telnet in XP

查看:82
本文介绍了在XP中通过telnet创建新进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


如何使用python通过telnet在XP中创建/生成新进程?

I.e。我想创建一个新的进程并让它在

后台运行...当我终止telnet连接时,我会将

生成的进程继续运行直到我关闭它...


我得到了os.popen方法来生成在

背景中运行的新进程,但不是通过telnet。 ..尝试了os.popen [2,3,4]以及

subprocesses.popen没有任何运气...


任何帮助将不胜感激。 .. thankyou。

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.

推荐答案



Godzilla写道:

Godzilla wrote:

您好,


如何使用python通过telnet在XP中创建/生成新进程?

即我想创建一个新的进程并让它在

后台运行...当我终止telnet连接时,我会将

生成的进程继续运行直到我关闭它...


我得到了os.popen方法来生成在

背景中运行的新进程,但不是通过telnet。 ..试过os.popen [2,3,4]还有

subprocesses.popen没有运气...
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...



我不喜欢我不知道你远程主机上有什么样的操作系统,你要远程登录

到。

这个想法归结为适当使用方法

来自`telnetlib.Telnet`类的`read_until`和`write`。


对于更复杂的东西你可以考虑使用pyexpect。


以下是连接到HP-UX的一个小示例。

您可以根据需要进行调整。


< code>

import telnetlib,time


def login(tn,login,passwd,prompt):

tn.rea d_until(" login:")

tn.write(login +" \\\
")

if passwd:

tn .read_until(" Password:")

tn.write(passwd +" \ n")

tn.read_until(提示)

time.sleep(2)

打印登录


def run_proc(tn,progname):

tn.write(" nohup%s& \\\
" %progname)

tn.write(" exit \ n")

print" program<%srunning" %progname


def kill_proc(tn,login,prompt,progname):

tn.write(" ps -u%s \ n"%登录)

buf = tn.read_until(提示)

pid = get_pid(buf,progname)

如果不是pid:

print" program<%snot killed" %progname

tn.write(" exit \ n")

return

tn.write(" kill -TERM%s \ n"%pid)

tn.write(" exit \ n")

print" program<%skill" %progname


def get_pid(buf,progname):

pid,comm = None,无

for line in buf。 split(" \ n"):

试试:

pid,_,_,comm = line.split()

除外ValueError:

继续

如果comm == progname:

返回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

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


2007年3月23日03:47:14 -0700,哥斯拉< go *********** @ gmail。编写:
On 23 Mar 2007 03:47:14 -0700, Godzilla <go***********@gmail.comwrote:

您好,


如何使用python通过telnet在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...



Ssh - 甚至是rsh - 这些东西比telnet更好。

出于某种原因,它们在Windows中不是标准的。


ssh某处某些带参数的命令

rsh某处带参数的命令


比较


telnet某处


然后执行类似期望的事情(基本上模拟

有人在telnet

会话中键入带参数的命令)。

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).


当我终止telnet连接时,我会将

生成的进程继续运行,直到我关闭它...
when I terminate the telnet connection, I would what the
spawned processes to keep running until I shut it off...



这是远程操作系统的功能;当它的终端

消失时,会发生什么情况不受客户端的控制。


/ Jorgen


-

// Jorgen Grahn< grahn @ Ph''nglui mglw''nafh Cthulhu

\ X / snipabacken.dyndns.org R''lyeh wgah ''nagl fhtagn!

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!


Jorgen Grahn写道:
Jorgen Grahn wrote:

2007年3月23日03:47:14 - 0700,哥斯拉< go *********** @ gmail.comwrote:
On 23 Mar 2007 03:47:14 -0700, Godzilla <go***********@gmail.comwrote:

>你好,

如何使用python通过telnet在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...



Ssh - 甚至是rsh - 是比telnet用于这些事情。

出于某种原因,它们在Windows中不是标准的。


ssh某处带有参数的命令

rsh某处某些命令带参数


相比


telnet某处


然后执行类似期望的事情(基本上模拟

有人在telnet

会话中键入带参数的某些命令)。


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).



+对于在XP下作为服务运行的sshd,看看CopSSH。


+希望启动过程没有''我想要一个GUI ...否则,看看UltraVNC运行

作为守护进程,并使用ssh进行端口重定向。

+ 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.


>
>

>当我终止telnet连接时,我会将生成的进程继续运行,直到我将其关闭...
>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.



也许进程启动工作可以通过运行为
Windows服务并等待端口(或Pyro)上的请求的Python程序来完成对象或Corba

对象...)。

无需telnet / ssh连接,无需注销问题。


照顾可能存在的安全问题:-)

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 :-)


这篇关于在XP中通过telnet创建新进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆