2

I wrote this one liner that allow me to start pageant and load all .ppk files from my %HOMEPATH%/.ssh folder

Here is it:

start pageant && timeout 1 && FOR %k in ("%HOMEPATH%\.ssh\*.ppk") do start pageant %k

The timeout is there to prevent multiple pageant instances ( WIN7 only, I know )

So this works when just running it from the command line. Pageant starts and all keys load.

But now i want to put it in a .bat file so that i can add it in my startup folder.

I tried all these combinations:

start pageant && timeout 1 && FOR %k in ("%HOMEPATH%\.ssh\*.ppk") do start pageant %k

start pageant
timeout 1
FOR %k in ("%HOMEPATH%\.ssh\*.ppk") do start pageant %k

start pageant && timeout 1 && FOR %k in ("C:%HOMEPATH%\.ssh\*.ppk") do start pageant %k

start pageant
timeout 1
FOR %k in ("C:%HOMEPATH%\.ssh\*.ppk") do start pageant %k

start pageant && timeout 1 && FOR %k in ("C:\Users\Willem\.ssh\*.ppk") do start pageant %k

start pageant
timeout 1
FOR %k in ("C:\Users\Willem\.ssh\*.ppk") do start pageant %k

I also tried several options on FOR and tried removing and adding start everywhere. And many more variations, i keep getting this error when the FOR loops runs

HOMEPATHk was unexpected at this time.

It's just not working when i try to run it through a .bat file. pageant.exe is added to my system32 folder, I'm using the latest stable version.

What rookie mistake am i missing here that this won't run from a batch file ?

1
  • 2
    In batch files for loop variables use the sintax %%k Commented Dec 12, 2013 at 11:18

2 Answers 2

1

Double up your % to %% while running as a batch file. It's a special character and must be escaped when run from batch, explaining why it works from the command line but not from batch file.

Sign up to request clarification or add additional context in comments.

Comments

0

It would be better to call pageant with multiple parameters, instead of calling it multiple times:

pageant %a %b %c %d ... 

It doesn't start any more if already opened.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.