Call Perl script from Python

后端 未结 5 1844
名媛妹妹
名媛妹妹 2020-12-08 11:37

I\'ve got a Perl script that I want to invoke from a Python script. I\'ve been looking all over, and haven\'t been successful. I\'m basically trying to call the Perl scrip

5条回答
  •  时光说笑
    2020-12-08 12:04

    Would you like to pass var as a parameter, on stdin or both? To pass it as a parameter, use

    subprocess.call(["./uireplace.pl", var])
    

    To pipe it to stdin, use

    pipe = subprocess.Popen("./uireplace.pl", stdin=subprocess.PIPE)
    pipe.communicate(var)
    

    Both code snippets require uireplace.pl to be executable. If it is not, you can use

    pipe = subprocess.Popen(["perl", "./uireplace.pl"], stdin=subprocess.PIPE)
    pipe.communicate(var)
    

提交回复
热议问题