[英]How to pass the user input in batch file?
I have following script. 我有以下脚本。
echo off
cd C:\Users\User_Name\Desktop\Encryption\Hemant test
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" --import PB_Key.gpg
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" -e Test.txt
But after that in command windows its asking me user Input as per following "Enter the User ID.End with an empty line:" 但是在此之后,在命令窗口中,它要求我按照以下“输入用户ID。以空行结尾的用户”输入:
As displayed at the image: 如图所示:
I have to pass the 'Test' value and click on enter. 我必须通过“测试”值,然后单击Enter。
But I am not able to pass the 'Test' value in above Batch script. 但是我无法在上面的批处理脚本中传递“测试”值。
Edit I have installed the newest GnuPG for windows ( gpg4win 3.1.1 ) 编辑我已经为Windows安装了最新的GnuPG( gpg4win 3.1.1 )
Which contains the following library versions: 其中包含以下库版本:
c:\app\security\GnuPG\bin\gpg.exe --version
gpg (GnuPG) 2.2.7
libgcrypt 1.8.2
As for your script it should look the following way 至于您的脚本,它应该看起来如下
@echo off
cd "C:\Users\User_Name\Desktop\Encryption\Hemant test"
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" --import PB_Key.gpg
set /p user_id=Please enter your user id:
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" -r "%user_id%" --encrypt Test.txt
Edit2 - showing whole workflow (notice that I have the key already there so there is a message, in Czech, that states that the key is without any changes) Edit2-显示整个工作流程(请注意,我已经有了密钥,所以在捷克语中有一条消息指出密钥没有任何更改)
My test.bat
我的
test.bat
@echo off
c:\app\security\GnuPG\bin\gpg.exe --import C:\app\security\GnuPG\mygpgkey_pub.gpg
set /p user_id=Please enter your user id:
c:\app\security\GnuPG\bin\gpg.exe -r "%user_id%" -e VERSION
Now the actual workflow: 现在是实际的工作流程:
C:\app\security\GnuPG>dir *.gpg
Volume in drive C is OSDisk
Volume Serial Number is 6C83-746F
Directory of C:\app\security\GnuPG
17.05.2018 13:55 6 731 mygpgkey_priv.gpg
17.05.2018 13:55 3 181 mygpgkey_pub.gpg
2 File(s) 9 912 bytes
0 Dir(s) 5 941 710 848 bytes free
C:\app\security\GnuPG>test.bat
gpg: klíč B6E8D7336780XXXX: "John Smith <john.smith@usa.net>" beze změn
gpg: Celkový počet zpracovaných klíčů: 1
gpg: beze změn: 1
Please enter your user id:John Smith
C:\app\security\GnuPG>dir *.gpg
Volume in drive C is OSDisk
Volume Serial Number is 6C83-746F
Directory of C:\app\security\GnuPG
17.05.2018 13:55 6 731 mygpgkey_priv.gpg
17.05.2018 13:55 3 181 mygpgkey_pub.gpg
17.05.2018 13:57 609 VERSION.gpg
3 File(s) 10 521 bytes
0 Dir(s) 5 941 673 984 bytes free
C:\app\security\GnuPG>cat VERSION.gpg
☻♀♥VsP┼ĎžI}☺ ˙w▬ďÍ[Łu a↓#ŇÜŔ~>Ö▬ľżŕ↔►►=*Q×♥+Ç$NôCČuy→8Ą' @⌂∟ĘŽ∟'ôż|→↑|Ţ↕ÄĄú4|-b >%ÄXľ♂Ť ŮLŤÍ♫∟"˛2ýś+¸ęęHDF\`+-BţYu˙:|ŽÝÍ♣%☺RďGX┼łŠX%?Łä÷äĘo'Ę|3.Ń<ě°§ó☻ÇKŰ+CăÉĆŚßźE˙Ń?bÔj§ž`<?Ř9c♦§Şś>Éb˛ (ďćžDŹ☻jí6♦§-ßÚŇ~♀"kfďxĺk)˘¨äŰ×▼N÷1 3"}Ä-sžóáe↓x.↓=mĘ?Đ'Á♥{>7c♫SA^I˛uÁi!$Źő/¶ˇ ÇŃyr☺¬+"F-+ílBn¨xŮ«%]"ól5‼ ☺Ë'►JT↓►ď6ÍŤjÍ|ßŃ"@m+/ ¤¶ĆvŐĂwł♦$Ăżçy% OÇŁŔóť¤"öbzB0X;♠˙/ăÁbĽH♦_@♣Ôă☻Ĺ◄Ł♣\▲
Ă♀é&/►Ë⌂RĚ 'Yô'Kô~Á˝H☻'´pBŚp▬q↓<ÎŃn2Ů *í«[ëťh×űŽ♠oˇ'ĎtČw♠ Sč Pń{vPąŻwĘŰ♣š♂♠↑Öĺ?Űc=¨%ÉöÜš▬űüR0¶ŕ[qäXOżOb%ÁóçĹ;áÄ☺ĹńLúŘ?i┼e3Qť┼{T%Ż<ďĚŇP☺~Çbéx{O☺Ä◄uM× -ۤ[┼^♦ëŐ˙Rđť<2]{\^Ö%E<ÄX4a_R*?^Ç►ë‼♠Ň2ŐČě?z.M 1ä▲ąěŞuźăŁ↔÷q+Ŕ#á'
C:\app\security\GnuPG>cat VERSION
gnupg
2.2.7
C:\app\security\GnuPG>
Edit 3 - To check if the key is imported 编辑3-检查密钥是否已导入
c:\\app\\security\\GnuPG\\bin\\gpg.exe --list-secret-keys --keyid-format LONG
You should get something like this: 您应该得到这样的内容:
C:/Users/userID/AppData/Roaming/gnupg/pubring.gpg
---------------------------------------------------
sec rsa4096/B6E8D7336780XXXX 2018-05-17 [SC]
ABEC1158A91C80AF5B716DCCB6E8D7336780XXXX
uid [ absolutní ] John Smith <john.smith@usa.net>
ssb rsa4096/56735087CF9EXXXX 2018-05-17 [E]
Edit 4 - non-interactive batch script: 编辑4-非交互式批处理脚本:
@echo off
set "user_id=John Smith"
cd "C:\Users\User_Name\Desktop\Encryption\Hemant test"
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" --import PB_Key.gpg
"C:\Program Files (x86)\GnuPG\bin\gpg.exe" -r "%user_id%" --encrypt Test.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.