WinSCP ExecuteCommand报告IsSuccess = true但ExitCode = 1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WinSCP ExecuteCommand报告IsSuccess = true但ExitCode = 1相关的知识,希望对你有一定的参考价值。

我试图使用Powershell的WinSCP连接到Ubuntu机器,上传shell脚本并运行它。在脚本中我有set -o errexit以确保它在失败时停止。我无意中在运行脚本时忘记使用sudo,因此像chmod u=rwx,g=,o= some-folder这样的命令失败,因为不允许SSH用户这样做。这是预期的,我可以看到脚本已经终止了它应该。

然而,从Powershell,我做了类似的事情:

$session = New-Object WinSCP.Session
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp;
    HostName = $HostName
    UserName = $UserName
    SshPrivateKeyPath = $SshPrivateKeyPath
    SshHostKeyFingerprint = $SshHostKeyFingerprint
}

$session.Open($sessionOptions)
...

$result = $session.ExecuteCommand("$remoteScriptPath '$argument1' '$argument2'")

# In the scenario above I would expect the Check() to fail.
# Instead it moves on without any visible errors.
$result.Check()

如上所述,Check()没有失败,所以我尝试调试并注意到$result看起来像:

[DBG]: PS D:>> $result

Output      : Some command output ...
              Some other command output ...
              ...
ErrorOutput : chmod: changing permissions of 'some-folder': Operation not permitted
ExitCode    : 1
Failures    : {}
IsSuccess   : True

这对我来说非常违反直觉。当IsSuccess不为0且ExitCode不为空时,ErrorOutput如何才真实?它是WinSCP中的错误还是我不理解的功能?

更新:按建议附加会话日志文件...

. 2019-02-17 20:07:46.981 --------------------------------------------------------------------------
. 2019-02-17 20:07:46.981 WinSCP Version 5.13.7 (Build 9125) (OS 10.0.17134 - Windows 10 Home)
. 2019-02-17 20:07:46.981 Configuration: nul
. 2019-02-17 20:07:46.982 Log level: Normal
. 2019-02-17 20:07:46.982 Local account: CAS-DESKTOPcas04
. 2019-02-17 20:07:46.982 Working directory: D:...deploymentmodulesWinSCP-5.13.7-Automation
. 2019-02-17 20:07:46.982 Process ID: 17304
. 2019-02-17 20:07:46.982 Command-line: "D:...deploymentmodulesWinSCP-5.13.7-Automationwinscp.exe" /xmllog="C:Userscas04AppDataLocalTempwscp2118.013C0D9E.tmp" /xmlgroups /xmllogrequired /nointeractiveinput /dotnet=5.13.7  /ini=nul /log=".sessionLog.txt"  /console /consoleinstance=_8472_19901400_109
. 2019-02-17 20:07:46.982 Time zone: Current: GMT+1, Standard: GMT+1 (Romance Standard Time), DST: GMT+2 (Romance Daylight Time), DST Start: 31/03/2019, DST End: 27/10/2019
. 2019-02-17 20:07:46.983 Login time: 17 February 2019 20:07:46
. 2019-02-17 20:07:46.983 --------------------------------------------------------------------------
. 2019-02-17 20:07:46.983 Script: Retrospectively logging previous script records:
> 2019-02-17 20:07:46.983 Script: option batch on
< 2019-02-17 20:07:46.983 Script: batch           on        
< 2019-02-17 20:07:46.983 Script: reconnecttime   120       
> 2019-02-17 20:07:46.983 Script: option confirm off
< 2019-02-17 20:07:46.983 Script: confirm         off       
> 2019-02-17 20:07:46.983 Script: option reconnecttime 120
< 2019-02-17 20:07:46.983 Script: reconnecttime   120       
> 2019-02-17 20:07:46.983 Script: open "sftp://userName@ubuntu-machine-host.name" -hostkey="<ssh-key>" -privatekey="<ssh-key-path>" -timeout=15 -rawsettings ExitCode1IsError="1"
. 2019-02-17 20:07:46.983 --------------------------------------------------------------------------
. 2019-02-17 20:07:46.983 Session name: userName@ubuntu-machine-host.name (Ad-Hoc site)
. 2019-02-17 20:07:46.983 Host name: ubuntu-machine-host.name (Port: 22)
. 2019-02-17 20:07:46.983 User name: userName (Password: No, Key file: Yes, Passphrase: No)
. 2019-02-17 20:07:46.983 Tunnel: No
. 2019-02-17 20:07:46.983 Transfer Protocol: SFTP
. 2019-02-17 20:07:46.983 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2019-02-17 20:07:46.983 Disable Nagle: No
. 2019-02-17 20:07:46.983 Proxy: None
. 2019-02-17 20:07:46.983 Send buffer: 262144
. 2019-02-17 20:07:46.983 SSH protocol version: 2; Compression: No
. 2019-02-17 20:07:46.983 Bypass authentication: No
. 2019-02-17 20:07:46.983 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2019-02-17 20:07:46.983 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom: 
. 2019-02-17 20:07:46.983 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2019-02-17 20:07:46.983 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2019-02-17 20:07:46.983 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2019-02-17 20:07:46.983 Simple channel: Yes
. 2019-02-17 20:07:46.983 Return code variable: Autodetect; Lookup user groups: Auto
. 2019-02-17 20:07:46.983 Shell: default
. 2019-02-17 20:07:46.983 EOL: LF, UTF: Auto
. 2019-02-17 20:07:46.983 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2019-02-17 20:07:46.983 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2019-02-17 20:07:46.983 SFTP Bugs: Auto,Auto
. 2019-02-17 20:07:46.983 SFTP Server: default
. 2019-02-17 20:07:46.983 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2019-02-17 20:07:46.983 Cache directory changes: Yes, Permanent: Yes
. 2019-02-17 20:07:46.983 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2019-02-17 20:07:46.983 DST mode: Unix
. 2019-02-17 20:07:46.983 --------------------------------------------------------------------------
. 2019-02-17 20:07:46.984 Looking up host "ubuntu-machine-host.name" for SSH connection
. 2019-02-17 20:07:46.989 Connecting to <machine-ip> port 22
. 2019-02-17 20:07:47.023 We claim version: SSH-2.0-WinSCP_release_5.13.7
. 2019-02-17 20:07:47.060 Server version: SSH-2.0-OpenSSH_7.6p1 Ubuntu-4
. 2019-02-17 20:07:47.060 Using SSH protocol version 2
. 2019-02-17 20:07:47.060 Have a known host key of type ssh-ed25519
. 2019-02-17 20:07:47.094 Doing ECDH key exchange with curve Curve25519 and hash SHA-256
. 2019-02-17 20:07:47.505 Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
. 2019-02-17 20:07:47.506 Host key fingerprint is:
. 2019-02-17 20:07:47.506 <host-fingerprint> <ssh-key>
. 2019-02-17 20:07:47.507 Host key matches configured key
. 2019-02-17 20:07:47.507 Initialised AES-256 SDCTR client->server encryption
. 2019-02-17 20:07:47.507 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2019-02-17 20:07:47.507 Initialised AES-256 SDCTR server->client encryption
. 2019-02-17 20:07:47.507 Initialised HMAC-SHA-256 server->client MAC algorithm
. 2019-02-17 20:07:47.614 Reading key file "<ssh-key-path>"
! 2019-02-17 20:07:47.615 Using username "userName".
. 2019-02-17 20:07:47.651 Server offered these authentication methods: publickey
. 2019-02-17 20:07:47.651 Offered public key
. 2019-02-17 20:07:47.684 Offer of public key accepted
! 2019-02-17 20:07:47.684 Authenticating with public key "imported-openssh-key"
. 2019-02-17 20:07:47.786 Sent public key signature
. 2019-02-17 20:07:47.821 Access granted
. 2019-02-17 20:07:47.821 Opening session as main channel
. 2019-02-17 20:07:48.434 Opened main channel
. 2019-02-17 20:07:48.500 Started a shell/command
. 2019-02-17 20:07:48.501 --------------------------------------------------------------------------
. 2019-02-17 20:07:48.501 Using SFTP protocol.
. 2019-02-17 20:07:48.501 Doing startup conversation with host.
> 2019-02-17 20:07:48.501 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2019-02-17 20:07:48.535 Type: SSH_FXP_VERSION, Size: 150, Number: -1
. 2019-02-17 20:07:48.535 SFTP version 3 negotiated.
. 2019-02-17 20:07:48.535 Unknown server extension posix-rename@openssh.com="1"
. 2019-02-17 20:07:48.535 Supports statvfs@openssh.com extension version "2"
. 2019-02-17 20:07:48.535 Unknown server extension fstatvfs@openssh.com="2"
. 2019-02-17 20:07:48.535 Supports hardlink@openssh.com extension version "1"
. 2019-02-17 20:07:48.535 Unknown server extension fsync@openssh.com="1"
. 2019-02-17 20:07:48.535 We believe the server has signed timestamps bug
. 2019-02-17 20:07:48.535 We will use UTF-8 strings until server sends an invalid UTF-8 string as with SFTP version 3 and older UTF-8 strings are not mandatory
. 2019-02-17 20:07:48.535 Limiting packet size to OpenSSH sftp-server limit of 262148 bytes
. 2019-02-17 20:07:48.535 Getting current directory name.
. 2019-02-17 20:07:48.535 Getting real path for '.'
> 2019-02-17 20:07:48.535 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
< 2019-02-17 20:07:48.568 Type: SSH_FXP_NAME, Size: 45, Number: 16
. 2019-02-17 20:07:48.569 Real path is '/home/userName'
. 2019-02-17 20:07:48.569 Startup conversation with host finished.
< 2019-02-17 20:07:48.569 Script: Active session: [1] userName@ubuntu-machine-host.name
> 2019-02-17 20:07:48.633 Script: pwd
< 2019-02-17 20:07:48.633 Script: /home/userName
> 2019-02-17 20:07:48.746 Script: call mktemp
< 2019-02-17 20:07:48.747 Script: Searching for host...
. 2019-02-17 20:07:48.747 [Shell] Looking up host "ubuntu-machine-host.name" for SSH connection
. 2019-02-17 20:07:48.747 [Shell] Connecting to <machine-ip> port 22
. 2019-02-17 20:07:48.781 [Shell] We claim version: SSH-2.0-WinSCP_release_5.13.7
< 2019-02-17 20:07:48.781 Script: Connecting to host...
. 2019-02-17 20:07:48.819 [Shell] Server version: SSH-2.0-OpenSSH_7.6p1 Ubuntu-4
. 2019-02-17 20:07:48.819 [Shell] Using SSH protocol version 2
. 2019-02-17 20:07:48.819 [Shell] Have a known host key of type ssh-ed25519
. 2019-02-17 20:07:48.853 [Shell] Doing ECDH key exchange with curve Curve25519 and hash SHA-256
. 2019-02-17 20:07:49.269 [Shell] Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
. 2019-02-17 20:07:49.270 [Shell] Host key fingerprint is:
. 2019-02-17 20:07:49.270 [Shell] <host-fingerprint> <ssh-key>
< 2019-02-17 20:07:49.270 Script: Authenticating...
. 2019-02-17 20:07:49.270 [Shell] Host key matches configured key
. 2019-02-17 20:07:49.270 [Shell] Initialised AES-256 SDCTR client->server encryption
. 2019-02-17 20:07:49.270 [Shell] Initialised HMAC-SHA-256 client->server MAC algorithm
. 2019-02-17 20:07:49.270 [Shell] Initialised AES-256 SDCTR server->client encryption
. 2019-02-17 20:07:49.270 [Shell] Initialised HMAC-SHA-256 server->client MAC algorithm
. 2019-02-17 20:07:49.383 [Shell] Reading key file "<ssh-key-path>"
! 2019-02-17 20:07:49.384 [Shell] Using username "userName".
< 2019-02-17 20:07:49.384 Script: Using username "userName".
. 2019-02-17 20:07:49.419 [Shell] Server offered these authentication methods: publickey
. 2019-02-17 20:07:49.419 [Shell] Offered public key
. 2019-02-17 20:07:49.453 [Shell] Offer of public key accepted
! 2019-02-17 20:07:49.453 [Shell] Authenticating with public key "imported-openssh-key"
< 2019-02-17 20:07:49.453 Script: Authenticating with public key "imported-openssh-key".
. 2019-02-17 20:07:49.556 [Shell] Sent public key signature
. 2019-02-17 20:07:49.591 [Shell] Access granted
. 2019-02-17 20:07:49.591 [Shell] Opening session as main channel
. 2019-02-17 20:07:50.201 [Shell] Opened main channel
. 2019-02-17 20:07:50.268 [Shell] Started a shell/command
< 2019-02-17 20:07:50.268 Script: Authenticated.
. 2019-02-17 20:07:50.268 [Shell] --------------------------------------------------------------------------
. 2019-02-17 20:07:50.268 [Shell] Using SCP protocol.
. 2019-02-17 20:07:50.268 [Shell] Doing startup conversation with host.
< 2019-02-17 20:07:50.268 Script: Starting the session...
. 2019-02-17 20:07:50.268 [Shell] Skipping host startup message (if any).
> 2019-02-17 20:07:50.269 [Shell] echo "WinSCP: this is end-of-file:0"
< 2019-02-17 20:07:50.269 [Shell] Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.15.0-1009-aws x86_64)
< 2019-02-17 20:07:50.269 [Shell]  * Documentation:  https://help.ubuntu.com
< 2019-02-17 20:07:50.269 [Shell]  * Management:     https://landscape.canonical.com
< 2019-02-17 20:07:50.269 [Shell]  * Support:        https://ubuntu.com/advantage
< 2019-02-17 20:07:50.269 [Shell]   System information as of Sun Feb 17 19:07:46 UTC 2019
< 2019-02-17 20:07:50.269 [Shell]   System load:  0.0               Processes:           96
< 2019-02-17 20:07:50.269 [Shell]   Usage of /:   41.7% of 7.69GB   Users logged in:     1
< 2019-02-17 20:07:50.269 [Shell]   Memory usage: 27%               IP address for eth0: 172.31.16.254
< 2019-02-17 20:07:50.269 [Shell]   Swap usage:   0%
< 2019-02-17 20:07:50.269 [Shell]  * 'snap info' now shows the freshness of each channel.
< 2019-02-17 20:07:50.269 [Shell]    Try 'snap info microk8s' for all the latest goodness.
< 2019-02-17 20:07:50.269 [Shell]   Get cloud support with Ubuntu Advantage Cloud Guest:
< 2019-02-17 20:07:50.269 [Shell]     http://www.ubuntu.com/business/services/cloud
< 2019-02-17 20:07:50.269 [Shell]  * Canonical Livepatch is available for installation.
< 2019-02-17 20:07:50.269 [Shell]    - Reduce system reboots and improve kernel security. Activate at:
< 2019-02-17 20:07:50.269 [Shell]      https://ubuntu.com/livepatch
< 2019-02-17 20:07:50.270 [Shell] 200 packages can be updated.
< 2019-02-17 20:07:50.270 [Shell] 96 updates are security updates.
< 2019-02-17 20:07:50.270 [Shell] Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings
< 2019-02-17 20:07:50.302 [Shell] WinSCP: this is end-of-file:0
. 2019-02-17 20:07:50.302 [Shell] Detecting variable containing return code of last command.
. 2019-02-17 20:07:50.302 [Shell] Trying "$status".
> 2019-02-17 20:07:50.302 [Shell] echo "$status" ; echo "WinSCP: this is end-of-file:0"
< 2019-02-17 20:07:50.335 [Shell] WinSCP: this is end-of-file:0
. 2019-02-17 20:07:50.335 [Shell] The response is not numerical exit code
. 2019-02-17 20:07:50.336 [Shell] Trying "$?".
> 2019-02-17 20:07:50.336 [Shell] echo "$?" ; echo "WinSCP: this is end-of-file:0"
< 2019-02-17 20:07:50.369 [Shell] 0
< 2019-02-17 20:07:50.369 [Shell] WinSCP: this is end-of-file:0
. 2019-02-17 20:07:50.369 [Shell] Return code variable "$?" selected.
> 2019-02-17 20:07:50.369 [Shell] printenv LANG ; echo "WinSCP: this is end-of-file:$?"
< 2019-02-17 20:07:50.403 [Shell] C.UTF-8
< 2019-02-17 20:07:50.403 [Shell] WinSCP: this is end-of-file:0
. 2019-02-17 20:07:50.403 [Shell] We will use UTF-8
. 2019-02-17 20:07:50.403 [Shell] Changing directory to "/home/userName".
> 2019-02-17 20:07:50.403 [Shell] cd "/home/userName" ; echo "WinSCP: this is end-of-file:$?"
< 2019-02-17 20:07:50.436 [Shell] WinSCP: this is end-of-file:0
. 2019-02-17 20:07:50.437 [Shell] Getting current directory name.
> 2019-02-17 20:07:50.437 [Shell] pwd ; echo "WinSCP: this is end-of-file:$?"
< 2019-02-17 20:07:50.470 [Shell] /home/userName
< 2019-02-17 20:07:50.470 [Shell] WinSCP: this is end-of-file:0
. 2019-02-17 20:07:50.470 [Shell] Startup conversation with host finished.
< 2019-02-17 20:07:50.470 Script: Session started.
. 2019-02-17 20:07:50.470 Executing user defined command on command session.
> 2019-02-17 20:07:50.470 [Shell] mktemp ; echo "WinSCP: this is end-of-file:$?"
< 2019-02-17 20:07:50.505 Script: /tmp/tmp.AqxvgxbvUK
< 2019-02-17 20:07:50.505 [Shell] /tmp/tmp.AqxvgxbvUK
< 2019-02-17 20:07:50.505 [Shell] WinSCP: this is end-of-file:0
> 2019-02-17 20:07:50.505 [Shell] pwd ; echo "WinSCP: this is end-of-file:$?"
< 2019-02-17 20:07:50.538 [Shell] /home/userName
< 2019-02-17 20:07:50.538 [Shell] WinSCP: this is end-of-file:0
. 2019-02-17 20:07:50.539 Changing directory to "/home/userName".
. 2019-02-17 20:07:50.539 Getting real path for '/home/userName'
> 2019-02-17 20:07:50.539 Type: SSH_FXP_REALPATH, Size: 21, Number: 272
< 2019-02-17 20:07:50.572 Type: SSH_FXP_NAME, Size: 45, Number: 272
. 2019-02-17 20:07:50.572 Real path is '/home/userName'
. 2019-02-17 20:07:50.572 Trying to open directory "/home/userName".
> 2019-02-17 20:07:50.572 Type: SSH_FXP_LSTAT, Size: 21, Number: 519
< 2019-02-17 20:07:50.605 Type: SSH_FXP_ATTRS, Size: 37, Number: 519
. 2019-02-17 20:07:50.605 Getting current directory name.
. 2019-02-17 20:07:50.605 Getting current directory name.
> 2019-02-17 20:07:51.152 Script: put  -nopermissions -preservetime -transfer="binary" -- "D:...deploymentscriptsmanual-setup.create-user.sh" "/tmp/tmp.AqxvgxbvUK"
. 2019-02-17 20:07:51.152 Copying 1 files/directories to remote directory "/tmp/" - total size: 612
. 2019-02-17 20:07:51.152   PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask: tmp.AqxvgxbvUK
. 2019-02-17 20:07:51.152   TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
. 2019-02-17 20:07:51.152   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2019-02-17 20:07:51.152 Getting real path for '/tmp/'
> 2019-02-17 20:07:51.152 Type: SSH_FXP_REALPATH, Size: 14, Number: 784
< 2019-02-17 20:07:51.186 Type: SSH_FXP_NAME, Size: 29, Number: 784
. 2019-02-17 20:07:51.186 Real path is '/tmp'
. 2019-02-17 20:07:51.186 File: 'D:...deploymentscriptsmanual-setup.create-user.sh' [2019-02-17T19:05:33.126Z] [612]
. 2019-02-17 20:07:51.187 Copying "D:...deploymentscriptsmanual-setup.create-user.sh" to remote directory started.
. 2019-02-17 20:07:51.187 Binary transfer mode selected.
. 2019-02-17 20:07:51.187 Opening remote file.
> 2019-02-17 20:07:51.187 Type: SSH_FXP_OPEN, Size: 44, Number: 1027
< 2019-02-17 20:07:51.220 Type: SSH_FXP_HANDLE, Size: 13, Number: 1027
> 2019-02-17 20:07:51.220 Type: SSH_FXP_WRITE, Size: 637, Number: 1542
> 2019-02-17 20:07:51.220 Type: SSH_FXP_CLOSE, Size: 13, Number: 1796
> 2019-02-17 20:07:51.220 Type: SSH_FXP_SETSTAT, Size: 40, Number: 1289
< 2019-02-17 20:07:51.253 Type: SSH_FXP_STATUS, Size: 24, Number: 1542
< 2019-02-17 20:07:51.253 Status code: 0
< 2019-02-17 20:07:51.286 Type: SSH_FXP_STATUS, Size: 24, Number: 1796
< 2019-02-17 20:07:51.286 Status code: 0
. 2019-02-17 20:07:51.286 Preserving timestamp [2019-02-17T19:05:33.000Z]
< 2019-02-17 20:07:51.286 Type: SSH_FXP_STATUS, Size: 24, Number: 1289
< 2019-02-17 20:07:51.286 Status code: 0
. 2019-02-17 20:07:51.286 Transfer done: 'D:...deploymentscriptsmanual-setup.create-user.sh' => '/tmp/tmp.AqxvgxbvUK' [612]
. 2019-02-17 20:07:51.286 Copying finished: Transferred: 612, Elapsed: 0:00:00, CPS: 0/s
> 2019-02-17 20:07:51.388 Script: call sudo chmod u=rwx /tmp/tmp.AqxvgxbvUK
. 2019-02-17 20:07:51.388 Executing user defined command on command session.
> 2019-02-17 20:07:51.388 [Shell] sudo chmod u=rwx /tmp/tmp.AqxvgxbvUK ; echo "WinSCP: this is end-of-file:$?"
< 2019-02-17 20:07:51.442 [Shell] WinSCP: this is end-of-file:0
> 2019-02-17 20:07:51.442 [Shell] pwd ; echo "WinSCP: this is end-of-file:$?"
< 2019-02-17 20:07:51.476 [Shell] /home/userName
< 2019-02-17 20:07:51.476 [Shell] WinSCP: this is end-of-file:0
. 2019-02-17 20:07:51.476 Changing directory to "/home/userName".
. 2019-02-17 20:07:51.476 Getting real path for '/home/userName'
> 2019-02-17 20:07:51.476 Type: SSH_FXP_REALPATH, Size: 21, Number: 2064
< 2019-02-17 20:07:51.509 Type: SSH_FXP_NAME, Size: 45, Number: 2064
. 2019-02-17 20:07:51.509 Real path is '/home/userName'
. 2019-02-17 20:07:51.509 Trying to open directory "/home/userName".
> 2019-02-17 20:07:51.509 Type: SSH_FXP_LSTAT, Size: 21, Number: 2311
< 2019-02-17 20:07:51.542 Type: SSH_FXP_ATTRS, Size: 37, Number: 2311
. 2019-02-17 20:07:51.542 Getting current directory name.
. 2019-02-17 20:07:51.542 Getting current directory name.
> 2019-02-17 20:07:51.628 Script: call /tmp/tmp.AqxvgxbvUK '<userName-to-create>' '<script-parameter>'
. 2019-02-17 20:07:51.628 Executing user defined command on command session.
> 2019-02-17 20:07:51.628 [Shell] /tmp/tmp.AqxvgxbvUK '<userName-to-create>' '<script-parameter>' ; echo "WinSCP: this is end-of-file:$?"
< 2019-02-17 20:07:51.705 Script: Adding user `<userName-to-create>' ...
< 2019-02-17 20:07:51.706 [Shell] Adding user `<userName-to-create>' ...
< 2019-02-17 20:07:51.706 Script: Adding new group `<userName-to-create>' (1001) ...
< 2019-02-17 20:07:51.706 [Shell] Adding new group `<userName-to-create>' (1001) ...
< 2019-02-17 20:07:51.718 Script: Adding new user `<userName-to-create>' (1001) with group `<userName-to-create>' ...
< 2019-02-17 20:07:51.719 [Shell] Adding new user `<userName-to-create>' (1001) with group `<userName-to-create>' ...
< 2019-02-17 20:07:51.745 Script: Creating home directory `/home/<userName-to-create>' ...
< 2019-02-17 20:07:51.745 [Shell] Creating home directory `/home/<userName-to-create>' ...
< 2019-02-17 20:07:51.745 Script: Copying files from `/etc/skel' ...
< 2019-02-17 20:07:51.746 [Shell] Copying files from `/etc/skel' ...
< 2019-02-17 20:07:51.771 Script: mkdir: cannot create directory ‘.ssh’: Permission denied
! 2019-02-17 20:07:51.771 [Shell] mkdir: cannot create directory ‘.ssh’: Permission denied
< 2019-02-17 20:07:51.772 [Shell] WinSCP: this is end-of-file:1
> 2019-02-17 20:07:51.772 [Shell] pwd ; echo "WinSCP: this is end-of-file:$?"
< 2019-02-17 20:07:51.805 [Shell] /home/userName
< 2019-02-17 20:07:51.805 [Shell] WinSCP: this is end-of-file:0
. 2019-02-17 20:07:51.805 Changing directory to "/home/userName".
. 2019-02-17 20:07:51.805 Getting real path for '/home/userName'
> 2019-02-17 20:07:51.805 Type: SSH_FXP_REALPATH, Size: 21, Number: 2576
< 2019-02-17 20:07:51.838 Type: SSH_FXP_NAME, Size: 45, Number: 2576
. 2019-02-17 20:07:51.838 Real path is '/home/userName'
. 2019-02-17 20:07:51.838 Trying to open directory "/home/userName".
> 2019-02-17 20:07:51.838 Type: SSH_FXP_LSTAT, Size: 21, Number: 2823
< 2019-02-17 20:07:51.871 Type: SSH_FXP_ATTRS, Size: 37, Number: 2823
. 2019-02-17 20:07:51.872 Getting current directory name.
. 2019-02-17 20:07:51.872 Getting current directory name.
> 2019-02-17 20:07:52.054 Script: exit
. 2019-02-17 20:07:52.054 Script: Exit code: 0
. 2019-02-17 20:07:52.054 Closing connection.
. 2019-02-17 20:07:52.054 Sending special code: 12
. 2019-02-17 20:07:52.054 Sent EOF message
. 2019-02-17 20:07:52.055 [Shell] Closing connection.
. 2019-02-17 20:07:52.055 [Shell] Sending special code: 12
. 2019-02-17 20:07:52.055 [Shell] Sent EOF message
答案

实际上,默认情况下,WinSCP不会将退出代码1视为错误。

使用WinSCP 5.14.1 beta及更高版本,您可以使用raw session settings ExitCode1IsError更改它:

$sessionOptions.AddRawSettings("ExitCode1IsError", "1")

以上是关于WinSCP ExecuteCommand报告IsSuccess = true但ExitCode = 1的主要内容,如果未能解决你的问题,请参考以下文章

IN 语句中的 Datacontext ExecuteCommand 参数

VSCode:使用 executeCommand 打开示例项目后,测试不会继续

我们可以在 WP8 的 SqlCE LinqToSQL 上调用 DataContext.ExecuteCommand(sqlQuery) 吗?

使用hdc命令进行查看或者安装应用的时候报错[Fail]ExecuteCommand need connect-key解决方法

使用hdc命令进行查看或者安装应用的时候报错[Fail]ExecuteCommand need connect-key解决方法

LeetCode --- 392. Is Subsequence 解题报告