1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

My difficulties with handling the clip:boad

Discussion in 'TCC/LE Support' started by holla, Oct 5, 2011.

  1. holla

    Joined:
    Nov 13, 2008
    Messages:
    17
    Likes Received:
    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:
    all@mylocation.com: 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
     

    Attached Files:

  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,300
    Likes Received:
    39
    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.
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,300
    Likes Received:
    39
    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:
     
  4. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,187
    Likes Received:
    11
    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.
     
  5. holla

    Joined:
    Nov 13, 2008
    Messages:
    17
    Likes Received:
    0
    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.

     
  6. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,300
    Likes Received:
    39
    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.
     
  7. DMcCunney

    Joined:
    Jun 7, 2008
    Messages:
    96
    Likes Received:
    3
    On Wed, Oct 5, 2011 at 2:05 PM, Charles Dye <> wrote:

    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.


    ______
    Dennis
     
  8. holla

    Joined:
    Nov 13, 2008
    Messages:
    17
    Likes Received:
    0
    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.
     

Share This Page