Python,在脚本和.exe之间传递变量

时间:2022-06-19 00:10:12

I have a python script: main.py, which executes a cx_frozen python script: test.exe I have created. main.py needs to send variables to test.exe. If the frozen script is able to send variables back that would be great too.

我有一个python脚本:main.py,它执行一个cx_frozen python脚本:我创建的test.exe。 main.py需要将变量发送到test.exe。如果冻结的脚本能够发回变量,那也很好。

I have, up to this point been saving out .txt files from main.py and accepting them from test.exe side. But now that I am introducing multithreading, I am concerned the instances of test.exe will collect information from the .txts intended for other instances of test.exe.

到目前为止,我已经从main.py中保存了.txt文件并从test.exe端接受它们。但是现在我正在介绍多线程,我担心test.exe将从.txts收集信息,用于其他test.exe实例。

I was wondering if this is possible? How do I tell main.py to send variables to test.exe accept them ... and, if possible, send them back to main.py

我想知道这是否可能?如何告诉main.py将变量发送到test.exe接受它们......如果可能的话,将它们发送回main.py.

Thanks

谢谢

1 个解决方案

#1


1  

The easiest way to send variables to a sub-program is using command line arguments or environment variables. If you want bidirectional communication you can use pipes to transmit the info that you are currently sending over the text files (even on Windows). The python subprocess (http://docs.python.org/library/subprocess.html) module is very good at that that sort of thing.

将变量发送到子程序的最简单方法是使用命令行参数或环境变量。如果您想要双向通信,您可以使用管道传输您当前通过文本文件发送的信息(即使在Windows上)。 python子进程(http://docs.python.org/library/subprocess.html)模块非常擅长那种事情。

#1


1  

The easiest way to send variables to a sub-program is using command line arguments or environment variables. If you want bidirectional communication you can use pipes to transmit the info that you are currently sending over the text files (even on Windows). The python subprocess (http://docs.python.org/library/subprocess.html) module is very good at that that sort of thing.

将变量发送到子程序的最简单方法是使用命令行参数或环境变量。如果您想要双向通信,您可以使用管道传输您当前通过文本文件发送的信息(即使在Windows上)。 python子进程(http://docs.python.org/library/subprocess.html)模块非常擅长那种事情。