【发布时间】:2022-01-03 02:05:41
【问题描述】:
我在 folder_a 中有一个文件,我想在 folder_b 中执行一个 bat/bash 文件。这将与朋友共享,所以我不知道他将从哪里运行文件。这就是为什么我不知道确切的路径。
folder_a
___
| |
| python.py
|folder_b
|___
| |
| bat/bash file
这是我的代码。它运行没有错误,但它不显示任何内容。
import os, sys
def change_folder():
current_dir = os.path.dirname(sys.argv[0])
filesnt = "(cd "+current_dir+" && cd .. && cd modules && bat.bat"
filesunix = "(cd "+current_dir+" && cd .. && cd modules && bash.sh"
if os.name == "nt":
os.system(filesnt)
else:
os.system(filesunix)
inputtxt = input()
if inputtxt == "cmd file":
change_folder()
我想尝试仅使用内置 Python 库。
【问题讨论】:
-
pushd ../modules? -
是的,我现在把它修好了'
-
什么是
c,modulesnt/modulesunix应该是filesnt/filesunix吗? -
@chepner 我有一个 os.system 作为 c 的快捷方式,是的,它是 filent 和 filesunix 我现在修复了它
-
在
change_folder()之后的最终:实际上在您的代码中吗?它应该抛出一个语法错误。