Reputation: 63
I can use the if (-e $file)
in perl script to tell if a file exists in linux or not.
I can run p4 fstat $file
in linux to tell if a file exists in perforce depot.
But how do I use perl script to check if a file is in perforce depot?
Upvotes: 1
Views: 1371
Reputation: 91
Based on the question asked, it appears that you could run the p4 command using Perl's system()
, or the exec()
method, or as described above using the "backticks" operator.
The backtics operator will allow you trap STDERR
and STDOUT
from the command, so that you can use it for whatever.
The other two will attempt run the command and give return values accordingly, as described in perldoc -f exec
So, typically what can be done is a command like:
p4 files $file
Followed by
echo $?
The second command will get you the exit status of the last shell command.
When using backticks you can also try these:
Windows: command-to-execute 2>NUL
Linux / OSX: command-to-execute 2> /dev/null
These will suppress STDERR
and give you the output only. If you use a "1" instead of a "2" you will suppress STDOUT
and get the error only.
Finally, if you want both, you can use:
Windows / Linux / macOS: command-to-execute 1>2&
This will concatenate STDOUT
and STDERR
.
So in short, you use Perl to run any existing program on any operating system, and there are multiple ways to process the result of that.
Upvotes: 2
Reputation: 71454
You can run a command from a Perl script with the backtick operator:
`p4 files $file`
This will work as a truthy check to see if a file exists in Perforce:
if (`p4 -F %depotFile% files "$file"`)
Note that this requires you to be logged in to the Perforce server before you run the script (if you can't connect you'll always get "false" from the above condition).
Upvotes: 4