Using Python to run executable and fill in user input

后端 未结 4 1233
太阳男子
太阳男子 2020-12-15 12:25

I\'m trying to use Python to automate a process that involves calling a Fortran executable and submitting some user inputs. I\'ve spent a few hours reading through similar

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-15 12:51

    your arguments should not be passed to communicate. they should be given in the call to Popen, like: http://docs.python.org/2/library/subprocess.html#subprocess.Popen

    >>> import shlex, subprocess
    >>> command_line = raw_input()
    /bin/vikings -input eggs.txt -output "spam spam.txt" -cmd "echo '$MONEY'"
    >>> args = shlex.split(command_line)
    >>> print args
    ['/bin/vikings', '-input', 'eggs.txt', '-output', 'spam spam.txt', '-cmd', "echo '$MONEY'"]
    >>> p = subprocess.Popen(args) # Success!
    

提交回复
热议问题