我正在編寫一個小型python腳本來自動學生作業評估。我有一個框架,其中提交的作業被解壓縮到一個臨時文件夾中,並且我的腳本被作爲參數調用臨時文件夾的路徑。在一些額外的文件,我需要再G ++在從子進程調用時無法解析路徑
我的腳本首先拷貝試圖粗略編譯C++代碼:
compilation_files = " ".join(glob.iglob("*.cpp"))
compilation_call = ["g++", "-std=c++14", compilation_files, "-o " + output_name]
subprocess.call(compilation_call)
g++
退出與此錯誤:
g++: error: tests-main.cpp tests-small1.cpp small1.cpp: No such file or directory
g++: fatal error: no input files
我相信文件存在(畢竟,glob
將無法找到它們,否則),並且該子進程在正確的目錄中執行。
我這樣做
print "ls: ", subprocess.check_output("ls")
print "pwd: ", subprocess.check_output("pwd")
print "files: ", compilation_files
來驗證文件確實存在,適當地稱爲和腳本是在正確的目錄中運行。
---編輯---
我可以通過傳遞shell=True
使腳本的工作,但也將手動意味着逃避的文件名殼。
您是否嘗試過將絕對路徑傳遞給g ++? –
@JensHöpken是的,同樣的錯誤。 (除了因爲漫長的路徑而長得多) – Xarn