2017-03-07 115 views
1

我試圖使用WinSCP.com自動化文件傳輸,這是一個有它的命令和參數的shell。 但自動腳本將從.cmd.bat文件運行。傳遞腳本命令/輸入到打開的WinSCP外殼

因此,這裏是我的自動化腳本:

C: 
CD "C:\Program Files (x86)\WinSCP" 
CALL WinSCP.com 

REM This opens a 
REM winscp> 
REM shell or process 

REM now theoretically I should be able to run the WinSCP commands 
REM but they are not being piped into the winscp shell 

open mypassword | [email protected] 

REM the last command is not being executed. 
REM Instead the script hangs on the newly opened WinSCP shell. 
REM There are other winscp commands such as put <file> <path> 

我的問題是如何判斷的WinSCP過程從批處理腳本文件,把命令open mypassword | [email protected]

哦和額外的:我想在最後殺死winscp process \ shell。這裏我不知道正確的術語。它是進程還是shell?

回答

1

如果要在批處理文件中使用WinSCP命令(而不是在使用/script開關引用的單獨腳本文件中),則可以使用WinSCP /command switch

winscp.com /ini=nul /command^
    "open sftp://myuser:[email protected]/"^
    "..." 
    "exit" 

您可以有WinSCP GUI generate a batch file template(如上所示)。


雖然推薦使用/command開關,你居然問的是這樣的:

(
    echo open sftp://[email protected]/ 
    echo mypassword 
    ... 
    echo exit 
) | winscp.com 

注意的行爲會在某些情況下不同,相較於/commands,因爲在標準輸入上提供命令時,WinSCP假定交互式(人爲)使用。這就是爲什麼你應該使用/commands

+0

謝謝!然而,'^'沒有被識別。任何其他方式來分割新行上的命令? – user640853

+0

它也總是詢問我是否要緩存主機密鑰。我該如何打開一個y? – user640853

+0

這是在Windows批處理文件中將命令拆分爲多行的唯一方式(也是正確的)。確保'^'是行中最後一個字符(後面沒有空格),並且在下一行的開始處有一些空格。 –