Thomas
Thomas

Reputation: 2534

Passing inputs to program prompt in a batch file

I am running simulations in parallel using mpich2. I've got rather stringent security on my workstation, and must register using a new password each time I run a simulation. I have to enter:

mpiexec -register

which then prompt me for a username, and then prompt me for a password. Unfortunately, there seem to be no way to pass the user/pass to mpiexec on a single line, e.g.

mpiexec -register user:pass

does not work.

I'm trying to prepare a batch file that can automatically pass the username and password to the mpiexec prompts, but I cannot seem to get it to work. I've tried various things like timeout /t 5 but that doesn't work.

Can anyone tell me how to pass these inputs to the mpiexec program prompts in a batch file?

Thanks!

EDIT: I think I am getting closer. I've tried

(
echo username 
echo password 
echo password 
) | mpiexec -register

which appears to be passing the username and password inputs to the mpiexec prompts. Program is still hanging at the next step however - not sure if that's a problem with the way I'm passing these or not.

Upvotes: 2

Views: 2070

Answers (1)

jeb
jeb

Reputation: 82192

You could redirect or pipe into mpiexec.
With redirection it's gets a bit nasty for user/password entries, as there are often unwanted (and unvisible) spaces at the line ends.

(
echo user
echo pwd
) | more > fetch.txt

Creates in fetch.txt

user<space>
pwd<space>

When you want to suppress the spaces use a file redirection instead

(
echo user
echo pwd
) > file.tmp
< file.tmp mpiexec -register

In both cases (redirection or pipe), you need to serve all inputs for the program, not only username and password.
You can't enter inputs from keyboard anymore.

Upvotes: 2

Related Questions