Call Perl script from Python

后端 未结 5 1871
名媛妹妹
名媛妹妹 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:08

    You could try the subprocess.call() method. It won't return output from the command you're invoking, but rather the return code to indicate if the execution was successful.

    var = "/some/file/path"
    retcode = subprocess.call(["./uireplace.pl", var])
    if retcode == 0:
        print("Passed!")
    else:
        print("Failed!")
    

    Make sure you're Perl script is executable. Otherwise, you can include the Perl interpreter in your command (something like this):

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

提交回复
热议问题