大佬教程收集整理的这篇文章主要介绍了windows – 在`shift`之后使用`%*`,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我想要一个反映移位效果的%*版本,我该怎么办?我明白我可以说移位后%1%2%3%4%5%6%7%8%9但是这似乎很愚蠢且有潜在危险,这限制了我固定数量的参数.
虽然这不是特定于python的问题,但我可能有必要理解我想要这种行为的原因是我必须编写一个批处理文件SELEctPython.bat来预先配置某些环境变量,以便导航babel我有不同的Python发行版(你必须以某种方式设置%PYTHONHOME%,%PYTHONPATH%和%PATH%才能调用Python二进制文件并确信你会获得正确的发行版).我当前的脚本适用于设置这些变量,但我希望能够在一行中调用它和Python – 例如:
SELEctPython C:\python35 pythonw.exe myscript.py arg1 arg2 arg3 ...
理想情况下,我希望我的批处理文件使用shift来“吃掉”第一个参数,相应地处理它并设置环境,然后自动链式执行由其余参数形成的字符串.原理类似于env在posix系统中包装命令的方式:
env FOO=1 echo $FOO # wrap the `echo` command to be executed in the context of specified environment setTings
到目前为止我有这个 – 最后一行是问题所在:
@echo off set "LOC=%CD% if not "%~1" == "" set "LOC=%~1 if exist "%LOC%\python.exe" goto :success echo "python.exe not found in %LOC%" goto :eof :success :: Canonicalize the resulTing path: pushd %LOC% set "LOC=%CD% popd :: Let Python kNow where its own files are: set "PYTHONHOME=%LOC% set "PYTHONPATH=%LOC%;%LOC%\Lib\site-packages :: Put Python's LOCATIOn at the beginning of the system path if it's not there already: echo "%PATH%" | findstr /i /b /c:"%PYTHONHOME%" > nul || set "PATH=%PYTHONHOME%;%PYTHONHOME%\Scripts;%PATH% :: Now execute the rest: shift if "%~1" == "" goto :eof %1 %2 %3 %4 %5 %6 %7 %8 %9 :: This is unsatsifactory - what if there are more than 9 arguments?
更新:感谢Stephan我的工作解决方案现在有以下更改的结束部分:
:: Now execute the rest of the arguments,if any: shift if @%1 == @ goto :eof set command= :BuildCommand if @%1 == @ goto :CommandFinished set "command=%command% %1" shift goto :BuildCommand :CommandFinished %command%
set "params=" :build if @%1==@ goto :cont shift set "params=%params% %1" goto :build :cont echo params are %params%
以上是大佬教程为你收集整理的windows – 在`shift`之后使用`%*`全部内容,希望文章能够帮你解决windows – 在`shift`之后使用`%*`所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。