簡體   English   中英

使用python調用cmd.exe蝙蝠狀命令

[英]Call a cmd.exe bat.-like command with python

我需要一些幫助...我的計算機上安裝了一個程序,我想調用該程序來計算一些東西並給我一個輸出文件...

在Matlab中,命令“ dos()”完成了我在Matlab中的cmd屏幕輸出。

我需要它在python中工作,但我做錯了。

data='file.csv -v'
db=' -d D:\directory\bla\something.db'
anw='"D:\Program Files\bla\path\to\anw.exe"' + db + ' -i' + data

“ anw”輸出是這樣的:

>>> anw

'"D:\\Program Files\\bla\\path\\to\\anw.exe" -d D:\\directory\\bla\\something.db -i file.csv -v' 
## without the "" it does not work either

import subprocess as sb    
p= sb.Popen('cmd','/K', anw) ## '/C' does not work either

我在python shell中從cmd.exe得到以下錯誤消息

Windows cannot find "\"D:\Program Files\bla\path\to\anw.exe"" Make sure you typed the name correctly, and then try again.

當我打蝙蝠時,這條線開始運行。 歸檔出來。 它通過“ dos(anw)”在matlab中運行,所以這里出了什么問題? ps:我的命令中有空格...這可能是問題嗎? 我不知道第一個“ \\”來自cmd。 exe錯誤信息

現在我制造了一只蝙蝠。 包含cmx.de所有內容的文件應在輸入文件所在的特定目錄中執行...

我只需要告訴python用

import os
os.chdir("D:\working\directory")
os.system(r'D:\working\directory\commands.bat')

它工作良好,並直接在python shell中給了我cmd的輸出

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM