Jump to content


Stopping notepad popup of tmp files while running change and other commands.

tmp files notepad change commands pipe batch

  • Please log in to reply
14 replies to this topic

#1 raysid

raysid

    Member

  • Members
  • PipPip
  • 12 posts

Posted 08 April 2015 - 08:19 AM

Hi.

I am a beginner in perforce and trying to perform some perforce commands using batch files in Windows environment.

The problem is, I want to run following commands without letting the perforce open up editor (notepad) to show tmp files.

Following is required to run in order.

1. p4 set P4CLIENT=[clientname]
2.p4 client -S [streamname] [clientname]
3.p4 client -t [clientname]
4.p4 sync [path of the client clientname\...#head]

The thing is, doing above always opens up the .tmp files for step 2 and 3.

I thought to use a work around by using -o and directing the output to console like this,
p4 client -S [streamname] -o [clientname]
p4 client -o -t [clientname]

The problem in doing this is, p4 sync is not syncing the clientname and its contents, but its syncing everything i.e every work-space.
Is there any way to avoid opening the tmp files either by redirecting the o/p or something else.

Also in another instance, how to provide input to a command from batch file for the following command,
p4 change

This opens up the notepad editor for editing the description part. But i want to provide the description in the batch itself without openning the tmp file for editing.

Please provide solution for the above two problems. Your help is highly appreciated. Please try to use Windows syntax in answering the queries if possible.

Thanks in advance.

#2 P4Sam

P4Sam

    Advanced Member

  • Members
  • PipPipPip
  • 484 posts
  • LocationSan Francisco, CA

Posted 08 April 2015 - 04:30 PM

What are you trying to do with step 3?  I think I understand everything else, but want to make sure I get your full intent before I try to come up with a set of commands to run.  :)

#3 P4Sam

P4Sam

    Advanced Member

  • Members
  • PipPipPip
  • 484 posts
  • LocationSan Francisco, CA

Posted 09 April 2015 - 07:05 PM

Okay, assuming I can just leave the "client -t" out without missing anything important, I think this is what you want to do:
p4 set P4CLIENT=[clientname]
p4 client -s -S [streamname]
p4 sync
This switches your client to the stream "[streamname]" and then syncs everything in the stream.  Note that the "-s" flag (for "switch") switches the client without invoking an editor.

There are a lot of details here of course -- the client will use its existing Root, if you had open files those will present problems (you probably don't want to just get rid of them by running "p4 revert"), etc.  If you run into problems of that nature post them here and we can come up with solutions, but for now I'll just assume that everything is nice and simple -- this is a client you've already created with a useful Root, your script is in control of it so it's safe to assume that it doesn't have any open files, etc.

To answer the more general question about how to avoid invoking an editor (e.g. for "p4 change"), an easy way to think of it is that when you run:
p4 change
it's the same as if you ran:
p4 change -o > tmpfile.txt
notepad tmpfile.txt
p4 change -i < tmpfile.txt
del tmpfile.txt

So if you want to skip the part where you invoke Notepad, run "p4 change -o" and "p4 change -i" and do something else in between to edit the spec.  The "-o" and "-i" flags work the same for every command that edits a spec -- the "-o" outputs the existing/default spec (without modifying it), and the "-i" inputs the new spec (saving it on the server).  In between the two if you're not invoking an editor you'll need to come up with some other way to modify the spec.

My personal favorite method is to use a Windows version of 'sed' and pipe the spec through it rather than dealing with temp files:

p4 change -o | sed -e "s/<.*>/my description/" | p4 change -i


#4 raysid

raysid

    Member

  • Members
  • PipPip
  • 12 posts

Posted 10 April 2015 - 06:22 AM

Sorry for delay in response.
In step 3 p4 client -t clientname is used with the intent to follow Copy client workspace clientname's view and options into the View: and Options: field of this workspace, as per Manual. My idea was to sync the view of client workspace with the view of server workspace.
But now, i think as i have already set the p4client env variable, and have performed step 2, so 3rd step is not required(if i am correct).
So skip 3rd step and tell me the solution.
Thanks for your quick response.

#5 raysid

raysid

    Member

  • Members
  • PipPip
  • 12 posts

Posted 10 April 2015 - 06:30 AM

Oh. Thanks for the reply with all the details. I will check out the solution and post if any thing goes wrong. :D

#6 P4Sam

P4Sam

    Advanced Member

  • Members
  • PipPipPip
  • 484 posts
  • LocationSan Francisco, CA

Posted 10 April 2015 - 07:15 PM

View Postraysid, on 10 April 2015 - 06:22 AM, said:

Sorry for delay in response.
In step 3 p4 client -t clientname is used with the intent to follow Copy client workspace clientname's view and options into the View: and Options: field of this workspace, as per Manual. My idea was to sync the view of client workspace with the view of server workspace.
But now, i think as i have already set the p4client env variable, and have performed step 2, so 3rd step is not required(if i am correct).
So skip 3rd step and tell me the solution.
Thanks for your quick response.

Correct -- the purpose of "client -t" is when you're creating a new client and want it to be a copy of some other client.  If you're currently using client A and you say "p4 client -t A" you're just saying to make A a copy of itself, which it already is.  :)

#7 raysid

raysid

    Member

  • Members
  • PipPip
  • 12 posts

Posted 16 April 2015 - 12:02 PM

Hi P4Sam.

As told by you in your post that "if you had open files those will present problems (you probably don't want to just get rid of them by running "p4 revert")" , I found that files are open and I don't want to get rid of them by running "P4 revert".

As per terminals suggestion when p4 client -s -S XYZ is run, it says  "Client 'XYZ' has files opened; use -f to force switch." can be used. :blink:

So would u tell a solution in this case !!

#8 raysid

raysid

    Member

  • Members
  • PipPip
  • 12 posts

Posted 16 April 2015 - 02:13 PM

I also faced a problem while creating p4 client. For eg. I did the following steps as captured in a text file from the .bat's stream.

1.p4 set P4CLIENT=abcd

2.p4 client -o  1>PerforceTmp.txt     (Read the stream into a text file though the actual command run in bat file was p4 client -o > PerforceTmp.txt)

3.p4 client -i  0<PerforceTmp.txt     (Read the stream into a text file though the actual command run in bat file was p4 client -i < PerforceTmp.txt)
Client abcd saved.

4.p4 client -s -S XYZ/JKH abcd
Client 'abcd' has a static view that will be overwritten; use -f to force switch.

5.p4 sync pathUptoParentOf_abcd\abcd\...#head

The problem is p4 sync is causing all the contents of stream XYZ into abcd (where abcd is workspace/empty folder created in client system before running the command order and doesn't exist at the depot), but what is needed is all the contents of XYZ/JHK into abcd.
Also tried using p4 client -s -S XYZ/JKH/ abcd but got the same results.

How to address this issue? please note step 3 and 4 are used to create a new client without opening a tmp file popup.

#9 P4Sam

P4Sam

    Advanced Member

  • Members
  • PipPipPip
  • 484 posts
  • LocationSan Francisco, CA

Posted 16 April 2015 - 02:23 PM

View Postraysid, on 16 April 2015 - 12:02 PM, said:

Hi P4Sam.

As told by you in your post that "if you had open files those will present problems (you probably don't want to just get rid of them by running "p4 revert")" , I found that files are open and I don't want to get rid of them by running "P4 revert".

As per terminals suggestion when p4 client -s -S XYZ is run, it says  "Client 'XYZ' has files opened; use -f to force switch." can be used. :blink:

So would u tell a solution in this case !!

It depends -- what do you want to do with the files if not revert them?  Right now they have edits that have not yet been submitted to the depot, and they're sitting on your local machine in the spot where you're about to try to put files from a different stream.  Something's got to give.  What do you want the final outcome to be?  Once we know that we can come up with the sequence of commands that will get you there.

View Postraysid, on 16 April 2015 - 02:13 PM, said:

I also faced a problem while creating p4 client. For eg. I did the following steps as captured in a text file from the .bat's stream.

1.p4 set P4CLIENT=abcd

2.p4 client -o  1>PerforceTmp.txt (Read the stream into a text file though the actual command run in bat file was p4 client -o > PerforceTmp.txt)

3.p4 client -i  0<PerforceTmp.txt (Read the stream into a text file though the actual command run in bat file was p4 client -i < PerforceTmp.txt)
Client abcd saved.

4.p4 client -s -S XYZ/JKH abcd
Client 'abcd' has a static view that will be overwritten; use -f to force switch.

Instead of those four commands, do these two:
  • p4 set P4CLIENT=abcd

  • p4 client -S //XYZ/JKH -o | p4 client -i
Your step 4 is failing because you've already created abcd as a non-stream ("classic") client with a static view and we don't want you to accidentally overwrite it with a generated stream view.  You could use "-f" to force it but it's easier to just create it as a stream client in the first place.  :)

Note that when creating a new client, the Root field is the current working directory by default -- it has no connection to the name of the client (abcd in your example).  You can override the working directory with the "-d" global option (global options go after the p4 and before the command name), like this:

p4 -d c:\asdf client -S //XYZ/JKH -o | p4 client -i

Or you can modify the client spec directly (this works for editing existing clients as well as creating new ones, but be very careful when editing the Root of a workspace that might already have files in it):

p4 client [options] -o | sed -e "s/Root:.*/Root: c:\\asdf/" | p4 client -i


#10 raysid

raysid

    Member

  • Members
  • PipPip
  • 12 posts

Posted 20 April 2015 - 10:28 AM

Quote

It depends -- what do you want to do with the files if not revert them?  Right now they have edits that have not yet been submitted to the depot, and they're sitting on your local machine in the spot where you're about to try to put files from a different stream.  Something's got to give.  What do you want the final outcome to be?  Once we know that we can come up with the sequence of commands that will get you there.

I would like to know both the conditions,

1.say few files i need to revert and few files i need to submit. So if i suppose i know which files to revert and so performed revert and if i know which files to submit, performed submit. After that doing the command " p4 client -s -S XYZ" will not have any issues. Right?

2.Now say in some case if i don't know or don't want to perform a submit or revert and want to get files without forcefully using a submit or revert (can be a case where few other users want a copy of the workspace in which they are working together without destroying or deciding over the changes made by other users in workspace), in that case how to use " p4 client -s -S XYZ".
This is one of the requirement as i am told. How to address this situation?

#11 raysid

raysid

    Member

  • Members
  • PipPip
  • 12 posts

Posted 20 April 2015 - 10:43 AM

View Postraysid, on 20 April 2015 - 10:28 AM, said:

I would like to know both the conditions,

1.say few files i need to revert and few files i need to submit. So if i suppose i know which files to revert and so performed revert and if i know which files to submit, performed submit. After that doing the command " p4 client -s -S XYZ" will not have any issues. Right?

2.Now say in some case if i don't know or don't want to perform a submit or revert and want to get files without forcefully using a submit or revert (can be a case where few other users want a copy of the workspace in which they are working together without destroying or deciding over the changes made by other users in workspace), in that case how to use " p4 client -s -S XYZ".
This is one of the requirement as i am told. How to address this situation?




Some points related to the above post.

1.Consider that the Stream is not changed for a already created workspace. But say the system User X is using can be shared by User Y. So he(Y) too chooses to perform " p4 client -s -S XYZ" in order to make sure the stream of the workspace is connected. So its just syncing with the chance of above 2 points.
2.If Y wants files from a different stream, in such a case Y wants to merge the contents of one existing stream which was earlier used by X and now with the data of new stream chosen by Y. Y may choose any 1 of the above 2 points.

#12 P4Sam

P4Sam

    Advanced Member

  • Members
  • PipPipPip
  • 484 posts
  • LocationSan Francisco, CA

Posted 20 April 2015 - 05:11 PM

It seems like it would be better (and much easier) for users X and Y to just have their own workspaces (two different workspaces on the same machine, with different root directories) rather than fighting over the same set of local files -- especially if they're both actively working on the files in two different streams!  Technically you could manage the switches by shelving and unshelving the files (or just use the "p4 switch" command in 2015.1, which does that automatically), but it doesn't solve the problem of what happens if the two users actually need to work at the same time.

#13 raysid

raysid

    Member

  • Members
  • PipPip
  • 12 posts

Posted 21 April 2015 - 06:25 AM

Ok. I am too believing that it would be easier for X and Y to have their own separate workspaces.

One more thing, once a new client workspace is created on a login and its stream is defined using "p4 client -S //XYZ/JKH -o | p4 client -i" and then after the user's work, the user logs off. My doubt is, for the next time when this user logs in and wants to use his newly created workspace without changing the stream, does this user needs to give or call any command for connecting to the stream defined earlier, or since the copy of workspace at the depot is already associated with the stream, so no such stream information is required before using the workspace for 2nd run/use? - Part 1.

If at all the user wants to change the stream, then he can use switch stream using " p4 client -s -S XYZ" kind of command right? With the case that files open for edit should be either submitted or reverted. In this case following order can be fine I believe;

1.p4 set P4CLIENT=[clientname]
2.p4 client -s -S [streamname]
3.p4 sync

For files open for edit, how to treat them, perform a revert before step 2 for the changes which can be undone, perform submit for files which can be submitted before step 2 and finally perform step 2? In the last case if he wants to force the switch without deciding on submit/revert, can step 2 be called with a force -f option? How? And what would be its implications? - Part 2.

Please ans the two part situations.

#14 P4Sam

P4Sam

    Advanced Member

  • Members
  • PipPipPip
  • 484 posts
  • LocationSan Francisco, CA

Posted 21 April 2015 - 02:45 PM

View Postraysid, on 21 April 2015 - 06:25 AM, said:

One more thing, once a new client workspace is created on a login and its stream is defined using "p4 client -S //XYZ/JKH -o | p4 client -i" and then after the user's work, the user logs off. My doubt is, for the next time when this user logs in and wants to use his newly created workspace without changing the stream, does this user needs to give or call any command for connecting to the stream defined earlier, or since the copy of workspace at the depot is already associated with the stream, so no such stream information is required before using the workspace for 2nd run/use? - Part 1.

The client spec that describes the workspace and its relationship to the stream is stored on the server, so all the user needs to do is have P4CLIENT set to the name of that same client.  The server remembers which stream that client goes with, which files are synced to the workspace and at what revisions, which files are open, et cetera.

Quote

If at all the user wants to change the stream, then he can use switch stream using " p4 client -s -S XYZ" kind of command right? With the case that files open for edit should be either submitted or reverted. In this case following order can be fine I believe;

1.p4 set P4CLIENT=[clientname]
2.p4 client -s -S [streamname]
3.p4 sync

For files open for edit, how to treat them, perform a revert before step 2 for the changes which can be undone, perform submit for files which can be submitted before step 2 and finally perform step 2? In the last case if he wants to force the switch without deciding on submit/revert, can step 2 be called with a force -f option? How? And what would be its implications? - Part 2.

Yes, once you've reverted and submitted all files, no files are open.  Note that another option beyond just discarding the files is to "p4 shelve" them before reverting them; you can then recover them later with "p4 unshelve".

If you do force the switch with "-f", the files remain open, in the old location.  That means that you will not be able to sync the files from the new stream into that location, so your workspace will be incomplete.  You also won't be able to submit the files from the old stream until you switch the client back.

As I mentioned earlier, the new 2015.1 release has a command called "p4 switch" that actually handles the shelving/unshelving for you.  You'd just do:

p4 set P4CLIENT=[clientname]
p4 switch [streamname]

and that would shelve any work you have in progress, switch to the new stream, and sync, all in one step.

#15 raysid

raysid

    Member

  • Members
  • PipPip
  • 12 posts

Posted 21 April 2015 - 04:51 PM

That's great. Thanks for the detailed replies. :)





Also tagged with one or more of these keywords: tmp files, notepad, change, commands, pipe, batch

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users