Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

My difficulties with handling the clip:boad

Nov
17
0
I am writing a scripts/aliases to write all passwords into a txt file and getting the text from the batch file.
My addpwd alias looks like: @echo %$ >> gpp1test.txt
My getpwd alias looks like: grep -i %$ gpp1test.txt
All is fine if I stop at this. When I type getpwd, the password is displayed, when I copy this from the console and paste into password fields in web, everything is fine.
The problem occurs when I try to copy the password into clipboard in a batch file.
The copy works, but when I paste, it also inserts one extra character into the clipboard. (I have to delete the last character manually to make it work)
I checked using clipspy, an external utility. This is how it shows up. (See attached image)
The one with blue tint are the images of clipboard where the text was copied to clipboard using "type ... > clip:" command. (That is what happens when I type "gpp1.bat all@")
The one with no tint are the ones when I mark the text on console and press enter. This is the one that works fine.
My gpp1.bat is the batchfile where I am trying to copy the password to clipboard, and looks like this:

@echo off
set gpptmpFile=%@UNIQUE[%tmp%]
del /q %gpptmpFile%
for /f "tokens=*" %a in ('grep -i %$ c:\gpp1test.txt') echo "%a" >> %gpptmpFile%
iff %@lines[%gpptmpFile%] ge 0 then
setdos /x-5
echo %@field[" :^"",-1,%@line[%gpptmpFile%,0]] > %gpptmpFile%.1
type %gpptmpFile%.1 > clip:
type %gpptmpFile%.1
del /q %gpptmpFile%.1
setdos /x0
else
echo Error: %@lines[%gpptmpFile%] lines in %gpptmpFile%
endiff
del /q %gpptmpFile%


My gpp1test.txt file is created using notepad++ and looks like this:
[email protected]: 4Something##&
another password: somethingElse%$#
One more: password!


Anyone has came across this problem when using clip:
I am on 32 bit intel based Windows vista.

Attached Images
 

Attachments

  • clips.jpg
    clips.jpg
    96.3 KB · Views: 265
Note that your passwords contain characters and combinations like & and $% which are significant to TCC. If you try manipulating these within TCC, you probably will have problems. Instead, since you're already using grep to pluck out the desired line, why not also use it to strip off the leading part (everything up to and including a colon and trailing whitespace) at the same time? Also note that, instead of redirecting to a temporary file, TYPEing the file to the clipboard, and deleting the temp file, you could just redirect grep's output directly to the clipboard.

This isn't related to your issue, but also note that you are deleting one temp file immediately before appending to it. Trying to append to a nonexistent file will fail if NoClobber is turned on.
 
Instead, since you're already using grep to pluck out the desired line, why not also use it to strip off the leading part (everything up to and including a colon and trailing whitespace) at the same time?
As usual, I'm confusing grep with sed....

Code:
@echo off
if %# == 0 ( echoerr Missing argument! & quit 1 )
sed -n "/%$.*:/Is/^.*: *//p" c:\gpp1test.txt > clip:
 
You might consider using the new @b64encode and @b64decode functions to keep the passwords a slight bit more secure than plaintext.

[C:\TC13] echo %@b64encode[s,password]cGFzc3dvcmQ=
-Scott
-----Charles Dye <> wrote: -----


Note that your passwords contain characters and combinations like & and $% which are significant to TCC. If you try manipulating these within TCC, you probably will have problems. Instead, since you're already using grep to pluck out the desired line, why not also use it to strip off the leading part (everything up to and including a colon and trailing whitespace) at the same time? Also note that, instead of redirecting to a temporary file, TYPEing the file to the clipboard, and deleting the temp file, you could just redirect grep's output directly to the clipboard.This isn't related to your issue, but also note that you are deleting one temp file immediately before appending to it. Trying to append to a nonexistent file will fail if NoClobber is turned on.
 
Thanks for your quick reply Charles.

My first version of batch file used to be a single line , something like ...
for /f "tokens=*" %a in ('grep -i %$ c:\gpp1test.txt') echo %@field[" :^"",-1,%a] >> clip:
Then I could not get the character "&" in passwords to work. So I had do this circus.

Anyway, I think I can find a windows port of sed and get this job done.

Note that your passwords contain characters and combinations like & and $% which are significant to TCC. If you try manipulating these within TCC, you probably will have problems. Instead, since you're already using grep to pluck out the desired line, why not also use it to strip off the leading part (everything up to and including a colon and trailing whitespace) at the same time? Also note that, instead of redirecting to a temporary file, TYPEing the file to the clipboard, and deleting the temp file, you could just redirect grep's output directly to the clipboard.

This isn't related to your issue, but also note that you are deleting one temp file immediately before appending to it. Trying to append to a nonexistent file will fail if NoClobber is turned on.
 
Anyway, I think I can find a windows port of sed and get this job done.

The one I'm using calls itself "super-sed version 3.62". I don't remember where I picked it up, but doubtless Google knows.
 
On Wed, Oct 5, 2011 at 2:05 PM, Charles Dye <> wrote:

> ---Quote (Originally by holla)---
> Anyway, I think I can find a windows port of sed and get this job done.
> ---End Quote---
> The one I'm using calls itself "super-sed version 3.62". *I don't remember where I picked it up, but doubtless Google knows.

The canonical source for sed is http://sed.sourceforge.net/ with
links to a variety of versions and ports, documentation, mailing
lists, tools, games, and sample scripts.

You can find super-sed there.


> Charles Dye
______
Dennis
 
Just to update:
I found @clipw which does what I want: (it does not add the extra 0d/0a)

for /f "tokens=*" %a in ('grep -i %$ %MyHome%\passwords-file.txt') set gpwd=%@clipw[%@field[" :^"",-0,%a]]

- That sets the last matching line; not perfect, but works for me for personal use.
 
Back
Top