如何通过代码运行批处理文件 [英] how can run batch file by code

查看:73
本文介绍了如何通过代码运行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我有一个批处理(.bat)文件.当我双击它时,它可以正常工作,但是当我通过代码Process.Start()执行它时,它却无法正常工作,我想通过代码来执行它.

感谢

hello
I have a batch(.bat) file. When I double click on it, it work correct but when I execute it by code Process.Start() it does not work correct and I want to execute it by code.

Thank

推荐答案

从程序运行批处理文件是一个奇怪的想法,几乎没有用:有许多其他方法可以集成软件或使代码可插入. >
因此,我从未尝试过.但是几秒钟前,出于好奇,我尝试了:

Running a batch file from a program is a strange idea and pretty much useless: there are many other way to integrate software or make codes pluggable.

So, I never tried it. But few seconds ago I tried, out of curiosity:

System.Diagnostics.Process.Start("mybatch.bat");



注意,我什至没有运行带有批处理文件作为参数的"CMD.EXE",而是尝试启动批处理文件本身(我认为这可能是一个问题).它立即起作用.不用说,我的可执行文件和批处理文件在同一目录中(请参阅Dave的注释).是吗?

—SA



Note, I didn''t even run "CMD.EXE" with the batch file as a parameter, I tried to start batch file itself (I thought this could be a problem). It worked immediately. Needless to say, I had my executable and the batch file in same directory (see Dave''s comment). Did you?

—SA


这篇关于如何通过代码运行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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