1
import sys
import os
import shutil


def main(argv):
    if len(argv) < 3:
        print("To few arguments")
        return 1
    dir = os.path.dirname(__file__)
    latencyMonitorDir = argv[1]
    feedManagerDir = argv[2]

    if not os.path.exists(dir + r"\Data"):
        os.makedirs(dir + r"\Data")
    if not os.path.exists(dir + r"\Data\Result"):
        os.makedirs(dir + r"\Data\Result")

    scriptCommand = "\"" + dir + "\\script.py\" " + latencyMonitorDir
    os.system(scriptCommand)
    if not os.path.isfile("\"" + dir + "\\Data\\BoostedFeedManager.exe\""):
        shutil.copy(feedManagerDir + r"\BoostedFeedManager.exe", dir + "\Data")

    scriptCommand = "\"" + dir + "\\Data\\BoostedFeedManager.exe\" " + "\"" + dir + "\\Data\\configInstruments.json\""
    print("debug")
    print(scriptCommand)
    os.system(scriptCommand)  # Error
    return 0


if __name__ == "__main__":
    sys.exit(main(sys.argv))

它会出错:

path is not recognized as an internal or external command, operable program or batch file.

当我不向路径添加引号时会出现此错误,但我正在这样做。错误位置由推荐“#Error”标记。

4

2 回答 2

0

From the documentation

Execute the command (a string) in a subshell. This is implemented by calling the Standard C function system(), and has the same limitations. Changes to sys.stdin, etc. are not reflected in the environment of the executed command.

Because if the error, the path probably doesnt exist, or it not a command/program. Try with os.path.exist(scriptCommand) if it exist.

于 2014-04-08T11:47:01.143 回答
0

使用 subprocess.getoutput('cmd')

于 2021-05-24T20:41:13.383 回答