【问题标题】:Python - Spawn/Run a New Process Using Shell's stdin and stdoutPython - 使用 Shell 的标准输入和标准输出生成/运行新进程
【发布时间】:2011-12-02 03:52:47
【问题描述】:

我想在 python 中执行一个非 python 程序。非 python 程序提示用户输入密码,因此我希望将 stdin 路由到该子进程。同样,子进程有一些我想打印到控制台的标准输出。当子进程终止时,我希望父 python 程序继续执行。

这看起来很简单,但我很难弄清楚如何去做。问题是有太多方法可以做非常相似的事情(os.spawn、os.exec、commands.、subprocess. 等)。

【问题讨论】:

  • 类似,但不完全相同。那个提问者想要一个可以在 IDLE 中工作的解决方案(这会使事情变得非常复杂),并且特别想使用 subprocess.Popen。

标签: python


【解决方案1】:
subprocess.call(whatever, stdin=sys.stdout, stdout=sys.stdin)

但是,您确定密码是通过标准输入输入的吗?命令行密码通常使用不同的工具。

【讨论】:

  • 刚刚测试过,我想这个rsync使用stdin。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-31
  • 1970-01-01
  • 2010-12-01
  • 2012-03-13
  • 1970-01-01
  • 1970-01-01
  • 2013-02-16
相关资源
最近更新 更多