English 中文(简体)
在您的 Python 脚本中运行命令行
原标题:Running command lines within your Python script

所以我有一堆化名和命令行提示程序, 我的主要程序是输入 b 到 cmd. exe 中, 然后是一些文件路径名称, 而不是什么。 我如何在我的 python 脚本中运行这些参数? 这样它就能模仿我在 cmd 中的行为?

最佳回答

您应该使用 < a href=> “ http://docs.python.org/library/sub process.html' rel=“ noreferrer” >sub process 模块。 特别是, < a href=" http://docs.python.org/library/sub process.html#subp process. recall" rel=“ noreferrer”> sub process. call 将为您运行命令行程序。 call < a>

问题回答

或您可以使用

import os
os.system( your_command )

例如:

import os
os.system( notepad )

将启动笔记本 与指挥线后面。

希望这能帮助

查看 < a href=> "http://sarge.readthedocs.org/en/latest/"rel="nofollow" >Sarge - a 折叠式子程序,旨在使需要与其Python代码的外部应用程序互动的人的生活更加轻松。 >Plumbum - 一个小型但具有特质丰富的图书馆,用于在Python的贝壳类脚本程序。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签