我很想做一些显而易见的事情,例如: 我有一个名为tsys2list的c程序当它被运行时,它要求用户给出tcal的值。这是一个变量。我想打电话给tsys2list在pyrthon脚本中,我们称之为gamma.py。 >>>但<<<我想传递tcal的值。自动编程,而不是通过与键盘的交互。 我该怎么做? 谢谢我提前! manolis
解决方案7月25日,7:56 * am,Emmanouil Angelakis< angel ... @ mpifr-bonn.mpg .de> 写道: 我很想做一些明显的事情琐碎如: 我有一个叫做tsys2list的交流程序当它被运行时,它要求用户给出tcal的值。这是一个变量。我想打电话给*" tsys2list"在pyrthon脚本中,我们称之为gamma.py。 >>>但<<<我想传递tcal的值。自动编程,而不是通过与键盘的交互。 我该怎么做? 谢谢我提前! manolis
有很多方法可以做到这一点。我建议在子进程模块中检查 ,看看它是否符合你的要求。或者你 可以学习一点Tkinter或wxPython并使用它来获得 用户的变量。或者您甚至可以通过命令行使用 raw_input进行操作。命令。 http:// docs。 python/lib/module-subprocess.html Mike
Mike Driscoll schrieb: 7月25日上午7:56,Emmanouil Angelakis< angel ... @ mpifr-bonn.mpg.de> 写道: > 我正在尝试做一些显而易见的事情,例如:我有一个名为tsys2list的交流程序;当它被运行时,它要求用户给出tcal的值。这是一个变量。我想打电话给tsys2list在pyrthon脚本中,我们称之为gamma.py。 >>>但<<<我想传递tcal的值。自动编程,而不是通过与键盘的交互。 我该怎么做? 谢谢我提前! manolis 有很多方法可以做到这一点。我建议在子进程模块中检查 ,看看它是否符合你的要求。
这只有在程序可以完全由 命令行参数控制时才有效。如果需要互动,OP可能会考虑使用pexpect 。
或者你 可以学习一点Tkinter或wxPython并使用它来获得 用户的变量。或者您甚至可以通过命令行使用 raw_input进行操作。命令。我没有看到*收集*输入(无论方法如何)如何解决 *传递*输入到子进程的问题。 Diez
2008-07-25,Diez B. Roggisch< de *** @ nospam.web .dewrote: >可能有很多方法可以做到这一点。我建议检查子进程模块,看看它是否符合您的要求。
这只有在程序可以完全由 命令行参数控制的情况下才有效。
为什么这么说?您可以使用子进程模块通过 stdin / stdout与程序进行交互。
如果需要交互,OP可能会考虑使用 pexpect。Pexpect是一个不错的选择,但它只是在子流程提供的相同设施之上的一个自动化层。 。 - 格兰特爱德华兹格兰特哇!我在THEORY有一个BIG BANG !! visi
Hi, I am tryiong to do something obviously trivial such as: I have a c program called "tsys2list" that when it is ran it asks the user to give the value of "tcal" which is a variable. I want to call the "tsys2list" from within a pyrthon script lets call it "gamma.py" >>>but<<< I want to pass the value of "tcal" to th eprogram automatically and not by interacting with the keyboard. How do I do that? thanks i advance! manolis
解决方案 On Jul 25, 7:56*am, Emmanouil Angelakis <angel...@mpifr-bonn.mpg.de> wrote: Hi, I am tryiong to do something obviously trivial such as: I have a c program called "tsys2list" that when it is ran it asks the user to give the value of "tcal" which is a variable. I want to call the *"tsys2list" from within a pyrthon script lets call it "gamma.py" >>>but<<< I want to pass the value of "tcal" to th eprogram automatically and not by interacting with the keyboard. How do I do that? thanks i advance! manolisThere are probably many ways to do this. I would recommend checking out the subprocess module and see if it does what you want. Or you could learn a little Tkinter or wxPython and use that to get the user''s variable. Or you could even do it via the command line using the "raw_input" command. docs.python/lib/module-subprocess.html Mike
Mike Driscoll schrieb: On Jul 25, 7:56 am, Emmanouil Angelakis <angel...@mpifr-bonn.mpg.de> wrote: >Hi,I am tryiong to do something obviously trivial such as:I have a c program called "tsys2list" that when it is ran it asks the user to give the value of "tcal" which is a variable. I want to call the "tsys2list" from within a pyrthon script lets call it "gamma.py" >>>but<<< I want to pass the value of "tcal" to th eprogram automatically and not by interacting with the keyboard.How do I do that?thanks i advance!manolisThere are probably many ways to do this. I would recommend checking out the subprocess module and see if it does what you want.
This will only work if the program can be fully controlled by commandline arguments. If interaction is required, the OP might consider using pexpect.
Or you could learn a little Tkinter or wxPython and use that to get the user''s variable. Or you could even do it via the command line using the "raw_input" command.I fail to see how *gathering* input (regardless of the method) solves the problem of *passing* input to a subprocess. Diez
On 2008-07-25, Diez B. Roggisch <de***@nospam.web.dewrote: >There are probably many ways to do this. I would recommendchecking out the subprocess module and see if it does what youwant.This will only work if the program can be fully controlled by commandline arguments.
Why do you say that? You can interact with programs via stdin/stdout using the subprocess module.
If interaction is required, the OP might consider using pexpect.Pexpect is a good option, but it''s just an automation layer on top of the same facilities that subprocess provides. -- Grant Edwards grante Yow! I''m having a BIG BANG at THEORY!! visi
更多推荐
从python中调用外部程序
发布评论