2014-10-06 42 views
4

使用QMake,我讀了一些鍋爐板代碼,進行修改並將修改後的代碼寫入文件。 但是,我得到了很奇怪的結果。我已將問題簡化爲以下內容:QMake - 不穩定的行爲當使用回聲系統命令

# Open boiler plate file 
interfaceBoilerPlateCode = $$cat($$boilerPlateFile, blob) 

# Make sure we read the right content 
message("Content read: $$interfaceBoilerPlateCode") 

# Write the read text into a file 
output = $$system(echo $$interfaceBoilerPlateCode >> $$targetFile) # Doesnt work 
output = $$system(echo "Howde" >> $$targetFile) # This works 

正在讀取的文件是僅包含字符串「Howde」的純文本文件。 文件的內容被正確讀取。但是,當我嘗試將文件的內容寫入另一個目標文件時,我得不到任何輸出(字面意思:沒有錯誤/警告,但沒有生成新文件)。然而,如果我只用代碼中定義的字符串(如上面代碼片段的最後一行)使用echo,則會在其中使用字符串「Howde」生成一個新文件。

這是怎麼回事?我做錯了倒數第二行不生成新文件?

+0

是否$$ interfaceBoilerPlateCode'需要在爲'echo'命令雙引號? – cmannett85 2014-10-06 12:02:55

+0

已經試過了。沒有效果。 – balajeerc 2014-10-06 12:06:11

回答

1

使用write_file。相反的:

$$system(echo $$content >> $$file_path) 

使用

write_file($$file_path, $$content)