Skip to content Skip to sidebar Skip to footer

/bin/sh: Line 62: To: Command Not Found

I have a python code in which I am calling a shell command. The part of the code where I did the shell command is: try: def parse(text_list): text = '\n'.join(text_list

Solution 1:

You rarely, if ever, want to combine passing a list argument with shell=True. Just pass the string:

synnet_output = subprocess.check_output("echo '%s' | syntaxnet/demo.sh 2>/dev/null"%(text,), shell=True)

However, you don't really need a shell pipeline here.

from subprocess import check_output
from StringIO import StringIO  # from io import StringIO in Python 3
synnet_output = check_output(["syntaxnet/demo.sh"],
                             stdin=StringIO(text),
                             stderr=os.devnull)

Solution 2:

There was a problem with some special characters appearing in the text string that i was inputting to demo.sh. I solved this by storing text into a temporary file and sending the contents of that file to demo.sh.

That is:

try:
    defparse(text_list):
        text = '\n'.join(text_list)
        cwd = os.getcwd()
        withopen('/tmp/data', 'w') as f:
            f.write(text)
        os.chdir("/var/www/html/alenza/hdfs/user/alenza/sree_account/sree_project/src/core/data_analysis/syntaxnet/models/syntaxnet")
        synnet_output = subprocess.check_output(["cat /tmp/data | syntaxnet/demo.sh 2>/dev/null"%text], shell = True)
        os.chdir(cwd)
        return synnet_output
except Exception as e:
    sys.stdout.write(str(e))

Post a Comment for "/bin/sh: Line 62: To: Command Not Found"