简体   繁体   English

Python:将路径作为参数传递

[英]Python: pass the path as an argument

i need to write a script in python, which run a process (notepad.exe). 我需要在python中编写一个脚本,该脚本运行一个进程(notepad.exe)。 The probelm is, i dont know the path of the process so i need to pass the path of the process as an argument. 问题是,我不知道进程的路径,因此我需要将进程的路径作为参数传递。

How does it work? 它是如何工作的?

The command-line arguments to your script are stored as a list in sys.argv . 脚本的命令行参数作为列表存储在sys.argv

To run a process, use the subprocess module. 要运行流程,请使用subprocess模块。

Try the following. 尝试以下方法。 In a file called exe.py put: 在名为exe.py的文件中:

import os 导入操作系统

import sys 导入系统

os.popen(sys.argv[1]) os.popen(sys.argv [1])

#

Usage: 用法:

C:\\Python32>python exe.py notepad.exe C:\\ Python32> python exe.py notepad.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM