![](/img/trans.png)
[英]Python: OSError: [Errno 2] No such file or directory: ''
[英]Python OSError: [Errno 2] No such file or directory ERROR
我在通過python在Linux上運行OS命令時遇到了麻煩(過去我花了很多時間)
我正在嘗試使用subprocess
模塊運行一個簡單的OS命令:
def test_func():
cmd = 'mkdir /tmp/test_dir'
res = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout.read()
我得到這個錯誤
Traceback (most recent call last):
File "/Volumes/fiverr_dev/fiverr-bi/apps/apis/api_acq_bing_reports.py", line 92, in <module>
acquisition_reports.test_func()
File "/Volumes/fiverr_dev/fiverr-bi/apps/etls/acquisition_reports.py", line 177, in test_func
res = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout.read()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
這突然開始發生。 我一直在處理python venv
s,也許它以某種方式影響了問題。
我嘗試在linux上運行的ANY命令都發生了錯誤。這似乎是一個非常普通的問題。
任何人都知道哪里出了問題?
您在python嘗試執行以下操作時遇到錯誤。
(ins)-> cmd='mkdir /tmp/hello'
(ins)-> "$cmd"
-bash: mkdir /tmp/hello: No such file or directory
在python中使用shlex.split(cmd)
In [13]: cmd = 'mkdir /tmp/hello'
In [14]: args = shlex.split(cmd)
In [15]: subprocess.Popen(args)
Out[15]: <subprocess.Popen at 0x10e1f74e0>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.