Page 1 of 1

Question on getting info to clipboard from a called command

Posted: 25 Sep 2013 19:32
by avsfan
Hi,

Background:
I currently use subversion, and I'd like to be able to copy one of my current workfiles to a file that includes the latest revision of that file in the name.

To get the information, I can just run
svn list -v "workfile.src"

and it'll return a line like:
1023 user 763342 Sep 18 10:20 workfile.src

And I wanted to copy workfile.src to (using the above example) workfile-v1023.src.

So, I figured I could do this with scripting. My first attempt looked like this:

Code: Select all

writefile("c:\bin\curver.bat", "svn list -v ""<curname>""|clip");
   run """cmd.exe"" /c ""c:\bin\curver.bat""", , 2, 0;
   delete 0, 0, "c:\bin\curver.bat";
   $mystr = <clipboard>;
   $mystr = trim($mystr);
   $myver = gettoken($mystr);
   copyas "*-v".$myver.".?";
This worked sometimes, and other times it would leave $myver as an empty string, leaving me with a file "workfile-v.src" (not desired)

Then I realized I should be able to do this without the batch file, so I tried this:

Code: Select all

run """d:\Program Files\TortoiseSVN\bin\svn"" list -v <curname>|clip", , 2, 0);
   $mystr = <clipboard>;
   $mystr = trim($mystr);
   $myver = gettoken($mystr);
   copyas "*-v".$myver.".?";
Unfortunately, it still didn't work.
I'm not sure what I'm doing wrong, but I'm sure it's a simple fix. I just can't see it.

Help, please!

Re: Question on getting info to clipboard from a called comm

Posted: 25 Sep 2013 22:01
by klownboy
Hi avsfan, I don't have or use SVN so it may be hard to help. It's probably just the syntax for your command. It can obviously be quite tricky especially the quoting, double quoting, and triple quoting. Take a look at the couple of examples near the bottom of this thread http://www.xyplorer.com/xyfc/viewtopic. ... 166#p91750 The examples may help you figure out what the issue is. Use "Step Mode" to aid you in figuring out the problem. The 2 examples both work and use "cmd /c" and "| clip" to get the output/results to the clipboard. Are you sure you shouldn't be using <curitem> in lieu of <curname> to get the entire path along with the filename.
Ken

Re: Question on getting info to clipboard from a called comm

Posted: 25 Sep 2013 22:49
by avsfan
klownboy wrote:Hi avsfan, I don't have or use SVN so it may be hard to help. It's probably just the syntax for your command. It can obviously be quite tricky especially the quoting, double quoting, and triple quoting. Take a look at the couple of examples near the bottom of this thread http://www.xyplorer.com/xyfc/viewtopic. ... 166#p91750 The examples may help you figure out what the issue is. Use "Step Mode" to aid you in figuring out the problem. The 2 examples both work and use "cmd /c" and "| clip" to get the output/results to the clipboard. Are you sure you shouldn't be using <curitem> in lieu of <curname> to get the entire path along with the filename.
Ken
hi Ken,

Thanks for your reply. I've tried both <curitem> and <curname> and the result is the same. I've tried running the command from a cmd.exe shell, and it works fine, sending the line to the clipboard. I've tried redirecting the output to a file (replacing the |clip with >myfile) and that works fine as well (sending the line to the specified file).

The fact that it worked for a while, then didn't, and then I changed something and it worked, and then didn't is what's really puzzling me. Perhaps I need to redirect to a file and then add run line that has something like "clip < myfile" and maybe that'll do the trick. I'm hoping one of the scripting masters can shed some light on what's happening...

Re: Question on getting info to clipboard from a called comm

Posted: 26 Sep 2013 02:35
by klownboy
Hi avsfan, are you sure the first line is functioning properly and consistently (i.e., what you expect is in the clipboard)? I ask because I'm still not sure about your quoting. With a file selected, run that first line by itself in a script or run it from the address bar with "stepping on". Then paste the contents of the clipboard into a blank text file to see what you have. Try that a number of times on a number of files.

I don't think you want to combine "| clip" and ">" redirection. If you go with redirecting to a file instead of clip, you could then use something like "readfile" and "copytext" to get the file contents into the clipboard...

Code: Select all

         $a = readfile (thefilename);   //read file created
         copytext $a, , "";           //copy the text to the clipboard
and then do your magic with trim and gettoken and copyas but look at the results of each line in "stepping" through the script. Again, good luck and sorry I can't be more specific since I don't have SVN. Maybe someone else does or at least knows specifically what the issue is.
Ken

Re: Question on getting info to clipboard from a called comm

Posted: 26 Sep 2013 03:34
by avsfan
klownboy wrote:Hi avsfan, are you sure the first line is functioning properly and consistently (i.e., what you expect is in the clipboard)? I ask because I'm still not sure about your quoting. With a file selected, run that first line by itself in a script or run it from the address bar with "stepping on". Then paste the contents of the clipboard into a blank text file to see what you have. Try that a number of times on a number of files.

I don't think you want to combine "| clip" and ">" redirection. If you go with redirecting to a file instead of clip, you could then use something like "readfile" and "copytext" to get the file contents into the clipboard...

Code: Select all

         $a = readfile (thefilename);   //read file created
         copytext $a, , "";           //copy the text to the clipboard
and then do your magic with trim and gettoken and copyas but look at the results of each line in "stepping" through the script. Again, good luck and sorry I can't be more specific since I don't have SVN. Maybe someone else does or at least knows specifically what the issue is.
Ken
Hi Ken,
Thanks again for your thoughts. You're absolutely right -- I definitely wouldn't do both the redirect and the pipe -- I'd just replace the pipe with the redirect. I've had this work very well for quite some time, and then it stopped... I'll take a look at running the lines from the address bar -- I knew that before, and then forgot about it, so thanks for refreshing my memory!

You're also right about the info not making it to the clipboard -- I've run the script(s) shown with stepping on, and the clipboard (today) is empty, whereas before, when it was working, it showed the correct string...

Time to break it down into even smaller steps and just make it work one step at a time...
EDIT:
I decided just to do the redirect (skipping the clipboard altogether), and it all works just as expected. For some reason, using the clip command from the script doesn't work. Here is what the resulting code looks like:

Code: Select all

writefile("c:\bin\curver.bat", "svn list --verbose ""<curitem>"">myver.txt");
   run """cmd.exe"" /c ""c:\bin\curver.bat""", , 2, 0;
   $mystr = readfile("myver.txt");
   delete 0, 0, "c:\bin\curver.bat";
   delete 0, 0, "myver.txt";
   $mystr = trim($mystr);
   $myver = gettoken($mystr);
   copyas "*-v".$myver.".?";
And this one works!

Re: Question on getting info to clipboard from a called comm

Posted: 26 Sep 2013 13:01
by klownboy
Hi avsfan, I'm glad you got the redirect / batch file version working. I'm still curious about the "clip" version though. After selecting a subject file, please try this one line in the address bar and see what's in the clipboard.

Code: Select all

  ::run "cmd /C """"d:\Program Files\TortoiseSVN\bin\svn"" list --verbose ""<curitem>"" | clip""",,2,0;
It may or may not be important, but I noticed in this last working version you used "--verbose" (with 2 dashes) whereas in the previous version you had "-v" (with one dash). Most programs are a bit finicky about the switches.
Ken

Re: Question on getting info to clipboard from a called comm

Posted: 26 Sep 2013 13:37
by avsfan
[quote="klownboy"]Hi avsfan, I'm glad you got the redirect / batch file version working. I'm still curious about the "clip" version though. After selecting a subject file, please try this one line in the address bar and see what's in the clipboard.

Code: Select all

  ::run "cmd /C """"d:\Program Files\TortoiseSVN\bin\svn"" list --verbose ""<curitem>"" | clip""",,2,0;
It may or may not be important, but I noticed in this last working version you used "--verbose" (with 2 dashes) whereas in the previous version you had "-v" (with one dash). Most programs are a bit finicky about the switches./quote]Hi Ken,
Actually, as with many *nix command, there are both short and long versions of the switches, so the -v and --verbose switches are identical, so that's not it.

However, I did notice that I can't paste ANY text in XY now -- not into the Address Bar, or script windows, or anywhere else. Pasting into other windows and applications works just fine... So perhaps XY is doing something strange with the clipboard on my system.

Will investigate...

Re: Question on getting info to clipboard from a called comm

Posted: 26 Sep 2013 15:29
by avsfan
avsfan wrote:However, I did notice that I can't paste ANY text in XY now -- not into the Address Bar, or script windows, or anywhere else. Pasting into other windows and applications works just fine... So perhaps XY is doing something strange with the clipboard on my system.

Will investigate...
OK, started a new XY with the /fresh option. Tried pasting something into the Address Bar (both with Ctrl-V and right-click->Paste), and neither of them would paste anything. I just got the list of available drives.

I also tried the same thing in the "Try Script" window and again, nothing would paste... I also copied the text of a filename, entered rename mode, and it wouldn't paste there, either...

Machine was just recently rebooted, and I am not seeing this error anywhere else -- I can paste everywhere else I expect to be able to.

Is anyone else seeing this strange behavior?

Using XY 12.90.0027.

Re: Question on getting info to clipboard from a called comm

Posted: 26 Sep 2013 17:18
by klownboy
I guess that would explain why you're having an issue using "|clip" in the script. I take it you're not using any type of clipboard manager. I don't know of anything either in Windows or XYplorer that would turn the clipboard capability off. They say the first thing you should do is open "notepad" and type some things and then try copying and pasting within notepad. Scan through some of these complaints about clipboard not working below. I don't know what you have on your system that could be causing the problem.
http://social.technet.microsoft.com/For ... ot-working
http://social.technet.microsoft.com/For ... ot-working
http://social.technet.microsoft.com/For ... y-or-paste
http://social.technet.microsoft.com/For ... -and-paste
Good luck!

Re: Question on getting info to clipboard from a called comm

Posted: 26 Sep 2013 17:30
by avsfan
klownboy wrote:I guess that would explain why you're having an issue using "|clip" in the script. I take it you're not using any type of clipboard manager. I don't know of anything either in Windows or XYplorer that would turn the clipboard capability off. They say the first thing you should do is open "notepad" and type some things and then try copying and pasting within notepad. Scan through some of these complaints about clipboard not working below. I don't know what you have on your system that could be causing the problem.
http://social.technet.microsoft.com/For ... ot-working
http://social.technet.microsoft.com/For ... ot-working
http://social.technet.microsoft.com/For ... y-or-paste
http://social.technet.microsoft.com/For ... -and-paste
Good luck!
Thanks again for your comments. As I mentioned before, pasting works just fine everywhere else, but not in XY -- that's what is so puzzling! And nope, no clipboard manager of any type. I even turned Listary off to make sure it wasn't stealing any keystrokes in XY, and that didn't make any difference. Definitely strange things going on...

Re: Question on getting info to clipboard from a called comm

Posted: 27 Sep 2013 13:29
by RalphM
I had a similar issue a while back.
Somehow the system language was changed and didn't correspond with my keyboard layout anymore, which understandably led to a lot of strange things to happen.
But since you state copy/paste works everywhere else on that machine, you probably got a different problem.