Python作为一个"分批QUOT;脚本(在Python即运行命令) [英] python as a "batch" script (i.e. run commands from python)

查看:115
本文介绍了Python作为一个"分批QUOT;脚本(在Python即运行命令)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows环境中工作(我的笔记本电脑!),我需要一对夫妇运行其他程序,pretty很像Windows批处理文件的脚本。

I'm working in a windows environment (my laptop!) and I need a couple of scripts that run other programs, pretty much like a windows batch file.

我如何从蟒蛇运行命令,运行程序时,将取代脚本?该方案是互动(例如,齐声)并保持印刷生产线,并要求用户输入的所有时间。

how can I run a command from python such that the program when run, will replace the script? The program is interactive (for instance, unison) and keeps printing lines and asking for user input all the time.

所以,只要运行程序和打印输出是不够的。该方案具有收购脚本的输入/输出,pretty mcuh就像从.bat文件运行命令。

So, just running a program and printing the output won't suffice. The program has to takeover the script's input/output, pretty mcuh like running the command from a .bat file.

我试过os.execl但它不断告诉我无效的参数,也没有找到(不搜索PATH变量)的程序名;我必须给它的完整路径..?!

I tried os.execl but it keeps telling me "invalid arguments", also, it doesn't find the program name (doesn't search the PATH variable); I have to give it the full path ..?!

基本上,在一个批处理脚本,我可以写:
齐声简介

basically, in a batch script I can write: unison profile

我如何能实现在Python同样的效果?

how can I achieve the same effect in python?

编辑:

我发现它可以与使用os.system来完成(...),因为我不能接受我自己的答案,我关闭的问题。

I found out it can be done with os.system( ... ) and since I cannot accept my own answer, I'm closing the question.

编辑:这应该是一个评论,但是当我张贴我没有太多的分

this was supposed to be a comment, but when I posted it I didn't have much points.

感谢Claudiu,这是pretty我想很多东西,除了一件小事:我希望函数结束程序退出时,但是当我尝试它步调一致,它不返回控制到蟒蛇剧本,但到Windows的命令行环境

Thanks Claudiu, that's pretty much what I want, except for a little thing: I want the function to end when the program exits, but when I try it on unison, it doesn't return control to the python script, but to the windows command line environment

>>> os.execlp("unison")

C:\>Usage: unison [options]
    or unison root1 root2 [options]
    or unison profilename [options]

For a list of options, type "unison -help".
For a tutorial on basic usage, type "unison -doc tutorial".
For other documentation, type "unison -doc topics".

C:\>
C:\>
C:\>

如何解决这个问题?

how to get around this?

推荐答案

我发现使用os.system我想要做什么,

I found out that os.system does what I want,

感谢所有那些试图帮助。

Thanks for all that tried to help.

os.system("dir")

运行命令,就好像它是从一个批处理文件运行

runs the command just as if it was run from a batch file

这篇关于Python作为一个"分批QUOT;脚本(在Python即运行命令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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