Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/enhancement: Problem in system calls and stdour/stderr redirection #25

Open
markelg opened this issue Sep 25, 2018 · 0 comments
Open

Comments

@markelg
Copy link
Contributor

markelg commented Sep 25, 2018

I found several problems in how this is handled right now in wrapper.py. The exec_cmd function used to call the shell uses subprocess.Popen shell=True option, but this by default uses the /bin/sh shell, even ignoring the default shell of the linux distro.

def exec_cmd( cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env = os.environ ):
logging.debug( "Executing command ... " + cmd )
p = subprocess.Popen( cmd, shell = True, stdout = stdout,
stderr = stderr, env = env )
output = p.stdout.read().strip() + p.stderr.read().strip()
code = p.wait()
return code, output

The problem is that /bin/sh does not recognize the typical syntax used in BASH to redirect standart output and standard error to a file:

/bin/sh -c "echo test >& test.txt"
/bin/sh: 1: Syntax error: Bad fd number

This causes the following line to fail in ubuntu, in other linux it may work (like centos) because /bin/sh is redirected to a shell compatible with this syntax:

code, output = exec_cmd( "ungribprocessor.%s >& %s" % ( pp, preprocessor_log ) )

The following line is also wrong because the "&>" is not redirecting the output to the log file.

code, output = exec_cmd( "preprocessor.%s %s %s %s %s &> %s" % (

We can either remove this "&" or set BASH to be the default shell to use by using the executable="/bin/bash" argument of subprocess.Popen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant