在批处理文件中将输入传递到程序提示符 [英] Passing inputs to program prompt in a batch file

查看:70
本文介绍了在批处理文件中将输入传递到程序提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mpich2并行运行模拟.我的工作站具有相当严格的安全性,每次运行模拟时都必须使用新密码进行注册.我必须输入:

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

然后提示我输入用户名,然后提示我输入密码.不幸的是,似乎没有办法在单行上将用户/密码传递给mpiexec,例如

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

不起作用.

我正在尝试准备一个批处理文件,该文件可以自动将用户名和密码传递给mpiexec提示符,但似乎无法正常工作.我已经尝试过诸如timeout /t 5之类的各种方法,但这是行不通的.

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.

谁能告诉我如何将这些输入传递给批处理文件中的mpiexec程序提示符?

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

谢谢!

我想我越来越近了.我已经尝试过

I think I am getting closer. I've tried

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

似乎正在将用户名和密码输入传递给mpiexec提示符.但是,程序仍然挂在下一步-不确定我传递这些内容的方式是否有问题.

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.

推荐答案

您可以重定向或管道到mpiexec.
重定向使用户/密码输入变得有点讨厌,因为在行尾经常有不需要的(和不可见的)空格.

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

fetch.txt

用户<space>
pwd <space>

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.

这篇关于在批处理文件中将输入传递到程序提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆