简体   繁体   English

将变量从Python脚本导入到批处理文件

[英]Import variable from Python script to Batch file

I have a python script containing vraibles example.py 我有一个包含脚本example.py的python脚本

"src = komponent/cool,
       komponent/raw"  /* path of source files */

and i have a batch file which needs to import the value of "src" for postporcessing example.bat 并且我有一个批处理文件,需要为后处理example.bat导入“ src”的值

--cs-include ='komponent/cool'* --cs-include ='komponent/raw'*

Is there any way to import directly between files (without using any other conversion) ? 有什么方法可以直接在文件之间导入(不使用任何其他转换)? "PyBat.bat" is one option but i am trying to figure out a better choice dont want to add on one more tool (not specifically)...as my project itself has too different files and interacting source. “ PyBat.bat”是一个选项,但我试图找出一个更好的选择,不想添加其他工具(不是专门)...因为我的项目本身文件和交互源太不同了。

Any help is appreciated.. Thank you in advance..!!! 任何帮助表示赞赏..提前谢谢.. !!!

In Python 在Python中
Create a temp batch file in %TEMP%\\setvars.bat containing SET commands to set environment vars. %TEMP%\\setvars.bat中创建一个临时批处理文件,其中包含用于设置环境变量的SET命令。 You could use subprocess.POpen to run an ECHO something > path batch command so that %TEMP% can be used. 您可以使用subprocess.POpen运行ECHO something > path batch命令,以便可以使用%TEMP%

In Batch 分批
Call the temp batch file : the vars are now available to use. Call临时批处理文件:现在可以使用vars了。

Solution is... 1.set a argument in the python itself. 解决方法是... 1.在python本身中设置一个参数。 2.call the batch file from python script and along with pass the argument using os.system(cmd) and cmd as a string. 2.从python脚本调用批处理文件,并使用os.system(cmd)和cmd作为字符串传递参数。

It will set the path itself. 它将设置路径本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM