无法使用执行shell命令子流程.Popen

2024-06-16 16:38:35 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图用子流程.Popen. 我犯了这个错误

In [3]: subprocess.Popen(["su - dhclient","eth0"])
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
/home/oae/<ipython-input-3-1cd768a39571> in <module>()
----> 1 subprocess.Popen(["su - dhclient","eth0"])

/usr/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    677                             p2cread, p2cwrite,
    678                             c2pread, c2pwrite,
--> 679                             errread, errwrite)
    680 
    681         if mswindows:

/usr/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
   1247                     if fd is not None:
   1248                         os.close(fd)
-> 1249                 raise child_exception
   1250 
   1251 

OSError: [Errno 2] No such file or directory

我该怎么解决这个问题?谢谢。在


Tags: inselfcloselibusrargssusubprocess