2017-01-16 66 views
0

我創建文件路徑如下所示:JS字符串不表現爲預期

'/Users/User/Documents/dev/engineerappcopy/VGimages/'+deviceName+'.png' 

這些文件路徑被傳遞給函數作爲參數,該函數使用的文件路徑在終端上執行的命令。

但是,該函數使用該字符串時似乎分成兩部分。出現此錯誤:

exec error: Error: Command failed: /bin/sh -c adb pull /sdcard/nexLogin.png /Users/User/Documents/dev/engineerappcopy/VGimages/josh 
.png 

/bin/sh: line 1: .png: command not found 

這是因爲'.png'已與主字符串分離。

+0

deviceName可能包含換行符或其他東西..但請張貼您的問題和您的努力來解決問題 –

+0

有沒有空間? – recurf

回答

1

deviceName變量的末尾刪除新行字符。您應該使用the trim method來執行此操作。

'/Users/User/Documents/dev/engineerappcopy/VGimages/' 
+ deviceName.trim() 
+ '.png' 
+0

謝謝,解決了上面的錯誤現在我有一個新的。但不相關,似乎無法找到新創建的圖像,但它以前用硬編碼名稱。 – recurf