| |
@@ -245,25 +245,23 @@
|
| |
quoted = shell_quote(encode(self.env_sh_path))
|
| |
command.stdin.write(b'. %s\n' % quoted)
|
| |
|
| |
- if self.command_prelude:
|
| |
- command.stdin.write(encode(self.command_prelude))
|
| |
-
|
| |
if stdin_text:
|
| |
command.stdin.write(b"echo -en ")
|
| |
command.stdin.write(_echo_quote(encode(stdin_text)))
|
| |
command.stdin.write(b" | ")
|
| |
|
| |
+ command.stdin.write(b'(')
|
| |
+ if self.command_prelude:
|
| |
+ command.stdin.write(encode(self.command_prelude))
|
| |
if isinstance(argv, basestring):
|
| |
# Run a shell command given as a string
|
| |
- command.stdin.write(b'(')
|
| |
command.stdin.write(encode(argv))
|
| |
- command.stdin.write(b')')
|
| |
else:
|
| |
# Run a command given as a popen-style list (no shell expansion)
|
| |
for arg in argv:
|
| |
command.stdin.write(shell_quote(encode(arg)))
|
| |
command.stdin.write(b' ')
|
| |
-
|
| |
+ command.stdin.write(b')')
|
| |
command.stdin.write(b'\nexit\n')
|
| |
command.stdin.flush()
|
| |
command.raiseonerr = raiseonerr
|
| |
Before the fix the prelude was executed in main shell and commands were
executed in nested shell only when they were passed as a string, not as a
list. There are two problems with this approach:
1. We can invoke run_command with argument ['false', ';', 'true'] which
is equivalent to 'false ; true' but the former will fail and later will
succeed which is confusing.
2. There are installations (particularly Cygwin) which have
/etc/bash.bash_logout containing invocation of "/usr/bin/clear".
This file is executed when user logs out. When run_command() send
"exit" command to remote shell, "clear" returns exit code 1 complaining
about TERM variable not being defined, which is normal for non-interactive
sessions. Without "set -e" option this is handled correctly and shell
returns result code of last executed user command. But with "set -e" shell
terminates prematurely and when user command succeeded we receive exit
status 1.
Executing "set -e" and user commands inside subshell solves both problems.