相当于 Windows 中的 Unix eval [英] Equivalent to Unix eval in Windows
问题描述
想知道您将如何在 Windows 中执行以下操作:
Was wondering how you'd do the following in Windows:
从 c shell 脚本(扩展 csh),我在 'eval' 方法中运行 Python 脚本,以便脚本的输出影响 shell 环境.看起来像这样:
From a c shell script (extension csh), I'm running a Python script within an 'eval' method so that the output from the script affects the shell environment. Looks like this:
eval `python -c "import sys; run_my_code_here(); "`
想知道如何使用 Windows 的内置 CMD shell 在 Windows 中执行类似 eval 语句的操作.我想在 Windows 脚本中运行 Python 脚本,并让脚本运行 Python 脚本打印出来的内容.
Was wondering how I would do something like the eval statement in Windows using Windows' built in CMD shell. I want to run a Python script within a Windows script and have the script run what the Python script prints out.
** 更新:指定对从 CMD shell 运行的兴趣.
** update: specified interest in running from CMD shell.
推荐答案
如果它在 cmd.exe
中,使用临时文件是唯一的选择 [据我所知]:
If it's in cmd.exe
, using a temporary file is the only option [that I know of]:
python -c "print(\"Hi\")" > temp.cmd
call temp.cmd
del temp.cmd
这篇关于相当于 Windows 中的 Unix eval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!