Reputation: 85
I am trying to find all the pendinglist files in my perforce depoth opened by me and if there are some pendingfiles in the pendinglist I want to execute :eof
funtion, if not I want to do something
I tried like this
@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
When I execute the above script. I can see the opened files printed on the console but after that the script throwing an error as - was unexpected at this time.
What should I do to get if there are some pendingfiles in the pendinglist I want to execute :eof
funtion, if not I want to do something
Upvotes: 0
Views: 237
Reputation: 71464
Disclaimer: I know Perforce very well, but .bat
syntax barely at all. I have no real idea of what any of that FOR
line is doing beyond the very general notion that it's iterating over the output of p4 opened
.
I think the issue is that your script expects p4 opened
to print just the filename, when the reality is that it prints output like this:
C:\Perforce\test>p4 opened ...
//stream/test/bar#1 - edit default change (text)
The error you're seeing is probably due to that FOR
statement trying to parse that line of output and tripping over the -
character.
A very easy fix is to use p4
's -F
global option to reformat the output into just the file path:
C:\Perforce\test>p4 -F %depotFile% opened ...
//stream/test/bar
hence:
@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
prints:
opened
files are in pending list, please submit them if needed or revert them
opened
Upvotes: 1