是否可以像在unix中一样在windows cmd中生成批处理文件?
我是一个unix的家伙,但我必须在windows中编写一个系统,我正试图编写一个脚本来移动一些文件。我试图让父批处理文件调用包含以下内容的子批处理文件:是否可以像在unix中一样在windows cmd中生成批处理文件?,windows,batch-file,call,Windows,Batch File,Call,我是一个unix的家伙,但我必须在windows中编写一个系统,我正试图编写一个脚本来移动一些文件。我试图让父批处理文件调用包含以下内容的子批处理文件: set REPORTFILE=c:\report.txt 然后我希望父级能够使用%REPORTFILE%变量。显然,CALL命令创建了一个新的上下文。 在unix中,您只需编写脚本的源代码,在windows中可以吗?如果我理解的话……这似乎适用于我在Vista中的工作: 呼叫器.bat echo this is the caller echo
set REPORTFILE=c:\report.txt
然后我希望父级能够使用%REPORTFILE%变量。显然,CALL命令创建了一个新的上下文。
在unix中,您只需编写脚本的源代码,在windows中可以吗?如果我理解的话……这似乎适用于我在Vista中的工作: 呼叫器.bat
echo this is the caller
echo initial value is: %reportfile%
call setter.bat
echo value is: %reportfile%
球棒
echo this is the value setter
set reportfile=c:\report.txt
C:\temp>调用者
C:\temp>echo这是呼叫者这是呼叫方
C:\temp>echo初始值为:
初始值为:
C:\temp>callsetter.bat
echo this is the value setter
set reportfile=c:\report.txt
C:\temp>echo这是值设置器这是值设置器
C:\temp>set reportfile=C:\report.txt C:\temp>echo值为:C:\report.txt
值为:c:\report.txt
更新为使用goto而不是parens:
if not exist file.txt goto doit
goto notfound
:doit
echo this is the caller
echo initial value is: %reportfile%
call setter.bat
echo value is: %reportfile%
goto end
:notfound
echo file found
:end
现在我想我可以做一些技巧,比如在unix REPORTFILE='cat filewithname.txt'中。(假装这些是背景信号)windows中有类似的吗?啊哈。。。是这个吗?set/p REPORTFILE=