子进程的原始输入
有没有办法获取 raw_input,将其记录到内存中,然后在子进程中调用它?
x = raw_input("what is your fav. Color??")
Subprocess.Popen("C://Windows/system32/cmd.exe")
os.system('echo your favorite color is "x"')
我对此的主要需求是这样我可以获取用户的 raw_input 并将其合并到我朋友制作的命令行程序中。
Is there a way to take a raw_input, record it to memory, then call it in a subprocess?
x = raw_input("what is your fav. Color??")
Subprocess.Popen("C://Windows/system32/cmd.exe")
os.system('echo your favorite color is "x"')
My main need for this is so that I can take a user's raw_input and incorporate that into a command line program my friend made.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,您使用
raw_input
获取输入,然后将其发送到 subprocess 命令,该命令正在调用您朋友的二进制文件,如下所示
Okay, you get your input using
raw_input
And then send it to subprocess command which is invoking your friend's binary like this
您可以将其作为命令行参数传递,如 Space_COwbOy 提到的,或者您可以打开一个管道,如果该子进程侦听 std-input,则设置子进程的 std-input,以便将其重定向到输出父进程的管道。然后,当您通过父进程的管道提供数据时,子进程将从父进程获取输出,就像从标准输入读取一样。
You could either pass it as a command-line parameter like Space_COwbOy has mentioned, or you could open a pipe, and if that sub-process listens on std-input, setup the std-input of the subprocess so that it's redirected to the output pipe of the parent process. Then when you feed the data through the pipe from the parent, the subprocess will pick up the output from the parent as if it was reading from standard-input.