简体   繁体   English

批处理脚本无法从.bat文件工作

[英]batch script not working from .bat file

I wrote this one liner that allow me to start pageant and load all .ppk files from my %HOMEPATH%/.ssh folder 我写了这个衬纸,使我可以开始选美并从我的%HOMEPATH%/.ssh文件夹加载所有.ppk文件

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 ) 那里的超时可以防止多个选美实例(仅WIN7,我知道)

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. 但是现在我想将其放在.bat文件中,以便可以将其添加到我的startup文件夹中。

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. 我还在FOR上尝试了几个选项,并尝试在任何地方删除和添加start。 And many more variations, i keep getting this error when the FOR loops runs 还有更多变化,当FOR循环运行时,我不断收到此错误

HOMEPATHk was unexpected at this time.

It's just not working when i try to run it through a .bat file. 当我尝试通过.bat文件运行它时,它不起作用。 pageant.exe is added to my system32 folder, I'm using the latest stable version. pageant.exe已添加到我的system32文件夹中,我使用的是最新的稳定版本。

What rookie mistake am i missing here that this won't run from a batch file ? 我在这里遗漏了什么新秀错误,那就是它不能从批处理文件运行?

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. 这是一个特殊字符,从批处理运行时必须转义,以解释为什么它从命令行而不是从批处理文件运行。

It would be better to call pageant with multiple parameters, instead of calling it multiple times: 最好使用多个参数来调用pageant,而不是多次调用它:

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

It doesn't start any more if already opened. 如果已经打开,它将不再启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM