Search code examples
node.jssubprocessspawnchild-process

Segmentation fault (core dumped) while calling python script from NodeJS through spawn


I have python script which prints out long list through statistical R (by PypeR). This python script is working absolutely fine.

Now I am trying to run this script from NodeJS through spawn functionality of child_process but it fails with following error:-

Traceback (most recent call last):
  File "pyper_sample.py", line 5, in <module>
    r=R()

  File "/home/mehtam/pyper.py", line 582, in __init__
    'prog' : Popen(RCMD, stdin=PIPE, stdout=PIPE, stderr=return_err and _STDOUT or childstderr, startupinfo=info), 
  File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__

    errread, errwrite)
  File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child

    raise child_exception
OSError: [Errno 2] No such file or directory

./temp.sh: line 1: 27500 Segmentation fault      (core dumped) python pyper_sample.py o1dn01.tsv cpu_overall

child process exited with code : 139

Note: My python script is working perfectly. I already tested it manually.


Solution

  • My python script is working perfectly. I already tested it manually.

    The output clearly shows that OSError: No such file or directory exception happened during Popen() call.

    It means that the program is not found e.g.,

    >>> from subprocess import Popen
    >>> p = Popen(["ls", "-l"]) # OK
    >>> total 0
    
    >>> p = Popen(["no-such-program-in-current-path"])  
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
        errread, errwrite)
      File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
        raise child_exception
    OSError: [Errno 2] No such file or directory
    

    Also, passing the whole command as a string instead of a list (shell=False by default) is a common error:

    >>> p = Popen("ls -l")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
        errread, errwrite)
      File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
        raise child_exception
    OSError: [Errno 2] No such file or directory
    

    Make sure:

    • your (child) program can be found in current $PATH
    • use a list argument instead of a string
    • test whether it works if you run it manually from a different working directory, different user, etc

    Note: your Popen() call passes startupinfo that is Windows only. A string command with several arguments that would work on Windows fails with the "No such file or directory" error on Unix.