Batch file 检查perforce中是否有挂起的文件,如果文件在挂起列表中,请转到eof,如果没有,请执行某些操作
我正在尝试查找我打开的Performance Depot中的所有pendinglist文件,如果pendinglist中有一些pendinglist文件,我想执行Batch file 检查perforce中是否有挂起的文件,如果文件在挂起列表中,请转到eof,如果没有,请执行某些操作,batch-file,cmd,perforce,Batch File,Cmd,Perforce,我正在尝试查找我打开的Performance Depot中的所有pendinglist文件,如果pendinglist中有一些pendinglist文件,我想执行:eof功能,如果没有,我想做点什么 我试过这样做 @echo off cls set P4CLIENT=<Workspace_name> set P4PORT=<IPadress:port> set P4USER=%username% set Depot_Path=//Depoth/path/... FOR
:eof
功能,如果没有,我想做点什么
我试过这样做
@echo off
cls
set P4CLIENT=<Workspace_name>
set P4PORT=<IPadress:port>
set P4USER=%username%
set Depot_Path=//Depoth/path/...
FOR /F "delims=" %%i IN ('p4 opened -u %username% //Depoth/path/...') DO set open_files=%%i
echo %open_files%
if %open_files% =="" (
echo No file are in pendig list
goto execute
) else (
echo files are in pending list, please submit them if needed or revert them
echo %open_files%
goto eof
)
:execute
<Do something>
:eof
@echo关闭
cls
设置客户端=
设置P4PORT=
设置P4USER=%username%
设置仓库路径=//Depoth/Path/。。。
对于/F“delims=“%%i IN('p4 opened-u%username%//Depoth/path/…'),请设置open_files=%%i
回显%open\u文件%
如果%open_文件%==“”(
echo挂起列表中没有文件
去执行
)否则(
回音文件在挂起列表中,请在需要时提交或还原
回显%open\u文件%
转到eof
)
:执行
:eof
当我执行上面的脚本时。我可以看到控制台上打印的打开的文件,但在此之后,脚本抛出一个错误为——此时是意外的。
如果挂起列表中有一些挂起文件我想执行
:eof
功能,我该怎么做才能得到,如果没有,我想做点什么
免责声明:我非常了解性能,但.bat
语法几乎没有。除了在p4 opened
的输出上进行迭代这一非常普遍的概念之外,我对FOR
行所做的任何事情都没有真正的了解
我认为问题在于,您的脚本希望p4 opened
只打印文件名,而实际情况是它打印的输出如下:
C:\Perforce\test>p4 opened ...
//stream/test/bar#1 - edit default change (text)
您看到的错误可能是由于FOR
语句试图解析该行输出并被-
字符绊倒所致
一个非常简单的修复方法是使用p4
的-F
全局选项将输出重新格式化为文件路径:
C:\Perforce\test>p4 -F %depotFile% opened ...
//stream/test/bar
因此:
@echo off
cls
FOR /F "delims=" %%i IN ('p4 -F ^%depotFile^% opened ...') DO set open_files=%%i
echo %open_files%
if %open_files% =="" (
echo No file are in pendig list
goto execute
) else (
echo files are in pending list, please submit them if needed or revert them
echo %open_files%
goto eof
)
:execute
<Do something>
:eof
您应该明确地将,
echo%open\u files%
和if%open\u files%==“
分别更改为echo(%open\u files%
和if”%open\u files%=“code>”。由于您已经定义了Depot\u路径
,您应该在p4
命令中使用它,如%Depot\u Path%”
。此外,您应该使用推荐的定义变量的方法,即设置“VarName=Var string value”
。最后,不要在文件中使用:eof
。:eof
默认为文件结尾标记,而不是标准标签,因此只要删除它,解析器就会知道irt的含义和去向。
opened
files are in pending list, please submit them if needed or revert them
opened