Skip to content
Advertisement

Search output of p4 command

I am trying to perform an action depending on the output of perforce commands. But it seems that pipping and greping/acking the command doesn’t appear to pickup the output

e.g.

JavaScript

Further example of what i’m trying to do:

JavaScript

Is there anyway to read the output of a perforce command without having to write to a file then read the output? Ideally the command would be a single line.

Advertisement

Answer

grep isn’t working because the “empty” messages like no such file and up-to-date go to stderr. As @heemayl suggested one way to fix that is to do a redirect.

You can also fix this in a shell-independent way by using the -s or -e flags to p4:

JavaScript

Both of these flags redirect all output to stdout and also prepend every message with debugging information about the message itself. If you’re trying to grep for a particular message, for example, you can use the -e flag and grep for its unique code rather than the string.

Using the -F flag lets you reformat the output to include particular elements from the message dict that you see with -e, so if you want just the code:

JavaScript

If you’re trying to capture elements of the actual output, like file names, -F is even more useful:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement