I have one script in Perl and the other in Python. I need to get the results of Perl in Python and then give the final report. The results from Perl can be scalar variable, hash variable, or an array.
我在Perl中有一个脚本,在Python中有另一个脚本。我需要在Python中获取Perl的结果,然后给出最终报告。 Perl的结果可以是标量变量,哈希变量或数组。
Please let me know as soon as possible regarding this.
请尽快告诉我有关此事。
4 个解决方案
#1
Use the subprocess module to run your Perl script to capture its output:
使用子进程模块运行Perl脚本以捕获其输出:
You can format the output however you choose in either script, and use Python to print the final report. For example: your Perl script can output XML which can be parsed by the Python script and then printed using a different format.
您可以在任一脚本中选择格式化输出,并使用Python打印最终报告。例如:您的Perl脚本可以输出XML,可以通过Python脚本解析,然后使用不同的格式打印。
#3
You could serialize the results to some sort of a string format, print this to standard output in the Perl script. Then, from python call the perl script and redirect the results of stdout to a variable in python.
您可以将结果序列化为某种字符串格式,将其打印到Perl脚本中的标准输出。然后,从python调用perl脚本并将stdout的结果重定向到python中的变量。
#4
Perhaps you want the answer to How can I read Perl data structures from Python?.
也许你想要答案我如何从Python中读取Perl数据结构?
#1
Use the subprocess module to run your Perl script to capture its output:
使用子进程模块运行Perl脚本以捕获其输出:
You can format the output however you choose in either script, and use Python to print the final report. For example: your Perl script can output XML which can be parsed by the Python script and then printed using a different format.
您可以在任一脚本中选择格式化输出,并使用Python打印最终报告。例如:您的Perl脚本可以输出XML,可以通过Python脚本解析,然后使用不同的格式打印。
#2
#3
You could serialize the results to some sort of a string format, print this to standard output in the Perl script. Then, from python call the perl script and redirect the results of stdout to a variable in python.
您可以将结果序列化为某种字符串格式,将其打印到Perl脚本中的标准输出。然后,从python调用perl脚本并将stdout的结果重定向到python中的变量。
#4
Perhaps you want the answer to How can I read Perl data structures from Python?.
也许你想要答案我如何从Python中读取Perl数据结构?