how to load a .bat file in c# windowapplication.thanks !!!

K99 2002-12-29 08:30:45
how to load a .bat file in c# windowapplication.thanks !!!
...全文
68 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
K99 2002-12-29
  • 打赏
  • 举报
回复
thanks,give grade!!
yarshray 2002-12-29
  • 打赏
  • 举报
回复
如果是读取就这样:

using System;
using System.IO;
class FileRead
{
string filereadbuf; // buffer to store the content of file

public void ReadFile(string FileName, int FileSize)
{
char[] buf = new char[FileSize]; // lets define an array of type char field (i.e. variable) buf

// for more help please see .net sdk
StreamReader sr = new StreamReader(new FileStream(FileName, FileMode.Open, FileAccess.Read));
int retval = sr.ReadBlock(buf, 0, FileSize); // no. of bytes read

Console.Write ("Total Bytes Read = " + retval + "\n");
filereadbuf = new string(buf); // store it in our field

Console.WriteLine (filereadbuf); // lets print on screen
sr.Close();

}
}

class TestFileRead
{
public static void Main(string[] args)
{
String[] cmdline = Environment.GetCommandLineArgs(); // Get the command line parameter
Console.WriteLine("File Reader Using Stream Reader & File Stream \n");

if (cmdline.Length < 2) // If no parameter is given will show user the usage
{
Console.WriteLine("Usage: " + cmdline[0] + " <input file> ");
return;
}
// Using Directory Class & using a Method GetFiles we get file list from the current directory
// return value is array of files please see .net sdk documentation for more help.
File[] fe = (new Directory(".")).GetFiles(cmdline[1]);

if (fe.Length == 0)
{
Console.WriteLine(cmdline[1] + ": file not found"); // if not found display a message to user
return;
}

FileRead fr = new FileRead();
try
{
fr.ReadFile(cmdline[1], (int)fe[0].Length); // sends 2 parameter filename & length
}
catch(IOException e){
Console.WriteLine("I/O error occured" + e);
return ;
}
} // Close brace of Main

} // close brace of TestFileRead


如果是执行就这样:
process.star("path/your.bat");
K99 2002-12-29
  • 打赏
  • 举报
回复
how to do,thanks

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧