I am trying to automate a command that prompts the users for their pin, the command in question;
tpmvscmgr.exe create /name "vSmartcard" /pin prompt /adminkey default generate
at this point you press enter, the next thing you see is
Enter Pin:
You enter the pin and press enter, then you get asked to confirm the pin before pressing enter again.
How can I automate this in a batch file, or in powershell? I haven't been able to find any commands that work in a similar way to even get a start on it.
I am not sure if the trick below work with your particular program; but even in this case, if the program prompts for an additional input it must be placed inside the parenheses next to the pin number. Perhaps this is enough for your needs...
#echo off
(
echo pinnum
echo pinnum
) | tpmvscmgr.exe create /name "vSmartcard" /pin prompt /adminkey default generate
Related
typing and executing a single line command in octave cli is simple.
for example a=1.
If one wants to edit this command and execute it again it is possible by navigating the history with the up/down keys.
But when executing a multi line command-script, one can still navigate to a single line and edit it, but how to execute the all script again, without going line by line in the history and "enter" the line?
for example:
for i=1:6
a(i) = i;
end
Is there a way to open the all script in an editor, edit, and re-execute it?
Yes there is, via the history command.
E.g. history -q 3 will display the last 3 commands -- the -q switch means do not prepend line numbers, such that the output is copy-pasteable.
You can also use the -w switch to redirect the output to a file, which you could then modify in your editor and call as a script, as you suggest.
If you're using the GUI, you can also use the history pane to highlight the lines you're interested in (in the order that you want them!), and paste directly into the editor window.
I am trying to write a MATLAB script that would call and run an external program and then proceed with other MATLAB commands.
tic %Start stopwatch
system('MyProgram.exe') %Call and run my program
toc %End stopwatch
However, this program "MyProgram.exe" requires me to "Press Enter to Exit." How to make my MATLAB script pass "Enter" to proceed? Like How to pass "Enter" as an input of my program at the end of execution? Or how to do this in general ?
On UNIX, you can use
system('MyProgram < /dev/null').
as suggested in the Matlab documentation:
To disable stdin and type-ahead redirection, include the formatted
text < /dev/null in the call to the invoked command.
The Windows equivalent is (based on this post):
system('MyProgram.exe < NUL')
When a console program needs to take input one time from the user and there is no built-in way to do so (like passing it in as an argument), that input can be echoed and piped to the program. This can also be used to press Enter (again, once) by piping a blank line.
echo.|program.exe
While traditionally a blank line is generated with echo by using the command echo., this can fail if the current directory contains a file called echo that has no extension. To get around this, you can use a ( instead of a ..
echo(|program.exe
I wrote a script to remote execute test.cmd file by PsExec.exe.
PsExec.exe \\IP -u administrator -p password "C:\\Users\Administrator\Desktop\test.cmd"
Although I can run the script successfully, I cannot press any key to continue the process when it runs into command pause.
Press any key to continue . . . aaaaaa
The only way to keep going is press Enter.
Besides, if there are many lines of Pause or set /p which waits users to input, once user press Enter, it will affect couple lines of Pause or set /p. It really confuses me.
Best is that you use different logic in accordance with your limitations.
Try exchanging the Pause with a different suitable solution.
Other suggestion would be that you share your code, inputs and expectations (output is already given - the script doesn’t continue). Then someone can review the code and suggest for further steps.
Alternatively, it is also possible that you can fix it by using Console.ReadKey()
I'm attempting to use epa mode and org mode in emacs as laid out by this article.
I'm attached to the computer using a screen session and ssh. I therefore needed to change /usr/bin/pinentry to point to /usr/bin/pinentry-curses as /usr/bin/pinentry-gtk-2.
I have
pinentry-program /usr/bin/pinentry-curses
as the last line in my .gnupg/gpg.conf. When I attempt to save the file I am presented with this menu:
Select recipients for encryption.
If no one is selected, symmetric encryption will be performed.
- `m' to mark a key on the line
- `u' to unmark a key on the line
[Cancel][OK]
I select 'ok' but only get
Opening output file: Encrypt failed, Exit
I get no prompt for my passphrase and no other output is given. It doesn't promp for a passphrase. It doesn't even list my gpg 'user' as foo#bar.com.
However when that line isn't present in the .gnupg/gpg.conf file I do see my gpg 'user' in the 'Select recipients for encryption' dialog. However, the cpu is pegged with the message stating:
Encrypting /home/user/test.gpg...
(I'm assuming as it is trying to spawn the gtk window and running in circles)
I'm a little confused as to why I needed to link /usr/bin/pinentry to /usr/bin/pinentry-curses and have the line in my gpg.conf file.
Before when /usr/bin/pinentry was linked to /usr/bin/pinentry-gtk-2, if I was on the local machine I'd get the 'Select recipients encryption' prompt with my gpg user listed. I'd get a dialog to input my passphrase and it all worked. I'd get
Encrypting /home/user/test.gpg...
and it would all succeed.
I'm running GNU Emacs 24.2.1 on an Arch system that is up to date as of this morning.
I'm curious what I'm doing wrong.
I've checked out the articles on pinentry and gpg on the arch wiki and they haven't helped to solve the problem.
Thanks in advance.
UPDATE: 26-10-2012 An update this morning to package cryptsetup seems to have influenced behavior. I now get A "Please enter passphrase" prompt when I open a .gpg file but it never seems to get past that. The prompt never goes away after entering my passphrase.
If this prompt comes from pinentry-curses, you might try:
1. enter passphrase (maybe not followed by enter, please try),
2. press tab key, 3. press enter key twice.
The reason for this is that you cannot see the whole form presented by pinentry-curses. Maybe try pinentry-curses outside emacs (and enter command GETPIN) to understand the blind navigation suggested above.
Similar problems exist if you use the Mew mail client (and gpg) inside emacs (in a terminal or tmux).
Anyone knows how to force the pinentry-curses dialog into one line suitable for emacs?
There are two main approaches, but their effectiveness may vary depending on the version of GPG used. This answer is for thecurrent modern branch (i.e. 2.2.x), not whatever was current when the question was asked.
Option 1a. Edit ~/.gnupg/gpg-agent.conf to use ncurses:
pinentry-program /usr/bin/pinentry-curses
Option 1b. Edit ~/.gnupg/gpg-agent.conf to use the Emacs pinentry (if available):
pinentry-program /usr/bin/pinentry-emacs
Option 2. Use the local gpg-agent and GUI over the SSH connection as described here
Option 2 takes a bit more effort to setup, but not too much and the benefits are considerable. Especially if you don't want to leave a secret key on a remote server.
In Matlab, there is a very nice feature that I like. Suppose I typed the command very-long-command and then a few several commands afterwards. Then later if I need the long command again, I just type very and press the up arrow key, my long command appears. It finds the last command that starts with very. I couldn't do the same in unix command line, when I try to do it, it disregards whatever I typed, and goes back to the last commands in chronological order. Is there a way to do it?
In bash this functionality is provided by the commands history-search-forward and history-search-backward, which by default are not bound to any keys (see here). If you run
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
it will make up-arrow and down-arrow search backward and forward through the history for the string of characters between the start of the current line and the point. See also this related Stack Overflow question.
In bash, hitting ctrl-r will let you do a history search:
$ echo 'something very long'
something very long
$ # blah
$ # many commands later...
(reverse-i-search)`ec': echo 'something very long'
In the above snippet, I hit ctrl-r on the next line after # many commands later..., and then typed ec which brought me back to the echo command. At that point hitting Enter will execute the command.
You can do the same thing by using "!". For example:
$ echo "Hello"
Hello
$ !echo
echo "Hello"
Hello
However, it is generally a bad idea to do this sort of thing (what if the last command did something destructive?). If you expect you will reuse something, then I suggest you create a shell script and save it away somewhere (whenever I plan to reuse something, I create a script in ~/.local/bin).