Retcode is 0 using shell=True

Issue #23 resolved
Dmitry Malinovsky created an issue
In [1]: from sarge import run

In [2]: p = run('exit 1', shell=True)

In [3]: p.returncode
Out[3]: 0

Comments (10)

  1. Vinay Sajip repo owner

    I cannot reproduce this using Python 2.7 / Python 3.4:

    vinay@machine:~/projects/sarge$ python
    Python 2.7.2+ (default, Jul 20 2012, 22:15:08) 
    [GCC 4.6.1] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from sarge import run
    >>> p = run('exit 1', shell=True)
    >>> p.returncode
    1
    >>> 
    vinay@machine:~/projects/sarge$ python3.4
    Python 3.4.1+ (3.4:606a18938476, Jun 25 2014, 13:11:32) 
    [GCC 4.6.1] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from sarge import run
    >>> p = run('exit 1', shell=True)
    >>> p.returncode
    1
    

    Can you provide more information? What does subprocess.Popen return in the same environment? What happens when you're not using IPython?

  2. Dmitry Malinovsky reporter

    Sure:

     $ python
    Python 3.3.4 (default, Feb 24 2014, 09:10:45) 
    [GCC 4.8.1] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from sarge import run
    >>> p = run('exit 1', shell=True)
    >>> p.wait()
    >>> p.returncode
    0
    >>> from subprocess import Popen
    >>> p = Popen('exit 1', shell=True)
    >>> p.communicate()
    (None, None)
    >>> p.returncode
    1
    
  3. Vinay Sajip repo owner

    Could you please run the following script and post the result and log file test_exit.log?

    import logging
    
    from sarge import run
    
    logging.basicConfig(level=logging.DEBUG, filename='test_exit.log',
                        filemode='w', format='%(asctime)s %(threadName)-10s %(name)-15s %(lineno)4d %(message)s')
    p = run('exit 1', shell=True)
    p.wait()
    print(p.returncode)
    
  4. Dmitry Malinovsky reporter

    The result is 0, and here is the log:

    2014-09-23 08:13:31,198 MainThread sarge.parse      799 starting parse of 'exit 1'
    2014-09-23 08:13:31,198 MainThread sarge.parse      941 returning CommandNode(command=['exit'] redirects={})
    2014-09-23 08:13:31,198 MainThread sarge.parse      941 returning CommandNode(command=['1'] redirects={})
    2014-09-23 08:13:31,198 MainThread sarge.parse      884 returning CommandNode(command=['exit', '1'] redirects={})
    2014-09-23 08:13:31,198 MainThread sarge.parse      867 returning CommandNode(command=['exit', '1'] redirects={})
    2014-09-23 08:13:31,198 MainThread sarge.parse      838 returning CommandNode(command=['exit', '1'] redirects={})
    2014-09-23 08:13:31,199 MainThread sarge.parse      822 returning CommandNode(command=['exit', '1'] redirects={})
    2014-09-23 08:13:31,199 MainThread sarge           1215 started: CommandNode(command=['exit', '1'] redirects={}), None, False
    2014-09-23 08:13:31,199 MainThread sarge            587 Command('exit 1') created
    2014-09-23 08:13:31,199 MainThread sarge            625 Popen: Command('exit 1'), {'stdin': None, 'stderr': None, 'shell': True, 'stdout': None} -> {'returncode': None, 'stdin': None, '_closed_child_pipe_fds': True, 'args': ['exit', '1'], '_communication_started': False, 'universal_newlines': False, '_child_created': True, 'stderr': None, '_input': None, 'pid': 12910, 'stdout': None}
    2014-09-23 08:13:31,200 MainThread sarge            643 about to wait for process
    2014-09-23 08:13:31,200 MainThread sarge            647 returning Command('exit 1') (Popen(returncode=0 stdin=None stdout=None stderr=None))
    2014-09-23 08:13:31,200 MainThread sarge           1049 pipeline closing
    2014-09-23 08:13:31,200 MainThread sarge           1034 pipeline waiting
    2014-09-23 08:13:31,200 MainThread sarge           1038 waiting for command
    
  5. Dmitry Malinovsky reporter

    Actually, the problem persists on py2.7 with the same log:

     $ python
    Python 2.7.5 (default, Jun  4 2014, 12:32:29) 
    [GCC 4.8.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from sarge import run
    >>> p = run('exit 1', shell=True)
    >>> p.wait()
    >>> p.returncode
    0
    
  6. Vinay Sajip repo owner

    Thanks for the update. Are you working with the last release, or the repo version? Changes were made to skip parsing where shell=True. The log from my run looks a little different:

    #!
    
    2014-09-22 22:46:06,829 MainThread sarge           1254 started: CommandNode(command=exit 1 redirects={}), None, False
    2014-09-22 22:46:06,830 MainThread sarge            586 Command('exit 1') created
    2014-09-22 22:46:06,830 MainThread sarge            622 About to call Popen: exit 1, {'shell': True, 'stdout': None, 'stdin': None, 'stderr': None}
    2014-09-22 22:46:06,835 MainThread sarge            625 Popen: Command('exit 1'), {'shell': True, 'stdout': None, 'stdin': None, 'stderr': None} -> {'_closed_child_pipe_fds': True, 'stdout': None, 'universal_newlines': False, 'stdin': None, '_child_created': True, 'pid': 18006, '_input': None, '_communication_started': False, 'returncode': None, 'args': 'exit 1', 'stderr': None}
    2014-09-22 22:46:06,835 MainThread sarge            644 about to wait for process
    2014-09-22 22:46:06,839 MainThread sarge            648 returning Command('exit 1') (Popen(returncode=1 stdin=None stdout=None stderr=None))
    2014-09-22 22:46:06,840 MainThread sarge           1088 pipeline closing
    2014-09-22 22:46:06,840 MainThread sarge           1074 pipeline waiting
    2014-09-22 22:46:06,840 MainThread sarge           1077 waiting for command Command('exit 1')
    
  7. Log in to comment