Получение NoSuchFile или Directory в подпроцессеPython

Программы на Python
Гость
Получение NoSuchFile или Directory в подпроцессе

Сообщение Гость »


I'm trying to run a CLI tool using

Код: Выделить всё

subprocess.run()
, but i'm getting irrelevant responses.

Folder structure

Код: Выделить всё

script.py mytools  |__tool_x  |__tool_y 
Case:1 Try to run the below command

Код: Выделить всё

import os import subprocess command = ["mytools/tool_x", "--help"] subprocess.run(                  command,                  stdout=subprocess.DEVNULL,                  cwd=os.path.dirname(__file__),              ) 
Result: It works as expected, gives no error.

Case-2:

Код: Выделить всё

import os import subprocess command = ["mytools/tool_x", "--subcommand", "test", "--subarg"] subprocess.run(                  command,                  stdout=subprocess.DEVNULL,                  cwd=os.path.dirname(__file__),              ) 
Result: Fails with

Код: Выделить всё

FileNotFoundError: [Errno 2] No such file or directory: 'mytools/tool_x'"

How can i resolve this, not able to find the issue, generally what are the possibilities for this issue?


Источник: https://stackoverflow.com/questions/781 ... subprocess

Вернуться в «Python»