如何在C#中通过单个批处理文件执行两个命令 [英] how to execute two command through single batch file in c#

查看:96
本文介绍了如何在C#中通过单个批处理文件执行两个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我必须执行一个批处理文件,首先在命令提示符下输入用户ID,然后再在相同的命令提示符下输入用户名I ENTER ,它要求输入密码.那么如何为这种情况编写批处理文件,以及如何通过C#中的批处理文件执行相同的条件呢?

I have to execute one batch file where first I am entering the User Id in command prompt and in the same command prompt after giving username I click ENTER and it is asking for the password. So how to write a batch file for this condition and how to execute the same condition through batch file in C#?

用户ID-C:\ Windows \ system32/ runas/user:edc \ ShashankR cmd

User Id - C:\Windows\system32/ runas /user:edc\ShashankR cmd

           输入edc \ ShashankR的密码: 测试

             Enter the password for edc\ShashankR: Test

在命令提示符下给出的突出显示区域上方,因此在给出之后 的runas/user:edc \ ShashankR cmd ,然后单击Enter(输入),要求输入密码,因此我给 测试.

above highlighted area I am giving in the command prompt so after giving runas /user:edc\ShashankR cmd  and I click enter it is asking for password so I am giving Test.

那么如何为这种情况编写批处理文件,以及如何通过C#中的批处理文件执行相同的条件?

So how to write a batch file for this condition and how to execute the same condition through batch file in C#?

谢谢

laxmikant

laxmikant

推荐答案

大多数脚本允许为批处理文件指定参数,并且仅在未指定参数时提示.我将从查看脚本开始,看看是否可以传递参数.如果是这样,那么当您从.NET调用脚本时,请传递适当的值.

Most scripts allow for specifying parameters to the batch file and only prompt if none are specified.  I'd start by looking at the script to see if you can pass parameters.  If so then pass the appropriate values when you call the script from .NET.

如果您需要将输入缓冲到批处理文件中,那么我建议您仅重定向标准输入流并传递所需的值.当脚本尝试读取输入时,它将获得您发送的内容.这个 MSDN代码演示了如何执行此操作.

If you need to buffer input to a batch file then I'd recommend that you simply redirect the standard input stream and pass the values that you need.  When the script tries to read the input it'll get what you sent it.  This MSDN code demonstrates how to do this.

迈克尔·泰勒
http://msmvps.com/blogs/p3net

Michael Taylor
http://msmvps.com/blogs/p3net


这篇关于如何在C#中通过单个批处理文件执行两个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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