Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

cmd - Check for pending files in perforce and if files are in pending list go to eof, if not Do something

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

question from:https://stackoverflow.com/questions/65872617/check-for-pending-files-in-perforce-and-if-files-are-in-pending-list-go-to-eof

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:Perforceest>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:Perforceest>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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...