下面是我编写的程序,本人是新手,将其存为exe 后在系统运行,没有错误提示,但是b.txt没被删除
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{Process p=new Process() ;
p.StartInfo .FileName ="cmd.exe" ;
p.StartInfo .UseShellExecute =false ;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.StandardInput.WriteLine("del c:\b.txt");
p.StandardInput.WriteLine("exit");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{Process p=new Process() ;
p.StartInfo .FileName ="cmd.exe" ;
p.StartInfo .UseShellExecute =false ;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.StandardInput.WriteLine("del c:\b.txt");
p.StandardInput.WriteLine("exit");
}
}
}
解决方案 »
- 如何用VLC的控件录像及截图 急!通过其它方式实现也行 需源码!
- c# 中可以利用FTP、 HTTP等方式下载文件请问服务器端怎么配置?
- 求算法
- 求链接,记得以前好像有个博客是写C#转JAVA的教程
- 问一个选号手机系统后台的问题
- 请问,怎样批量设置菜单里所有的ITEM 的enable为FALSE?
- 面板控件问题
- 请问用什么方法把图片根据取出的路径显示到IMAGE控件上,谢谢
- 在C#应用程序中,添加web引用,出现自定义工具警告: DiscoCodeGenerator 无法初始化代码生成器,没有生成任何代码.向Form添加Dataset时,找
- What is the meaning of the instance of a interface?
- 关于字符串的倒序输出
- asp.net 验证用户登录传的用户密码都正确为什么返回的k=-1
CMD命令窗口就是WINDOWS自带的程序。。
System.IO.File }
p.StandardInput.WriteLine("del c:\b.txt");
p.StandardInput.WriteLine("exit");
这两句根本就不是执行删除文件的,只不过是将这两行字打出来。你得自己建一个exe 里面是删除文件的。例如class Program
{
static void Main(string[] args)
{ string filepath = args[0];
File.delete(filepath); }
}
这段代码生成的EXE文件,比如叫filedelete.exe用上面那段代码进行调用,把那个
p.StartInfo .FileName ="cmd.exe" ;
cmd.exe的信息换成filedelete.exe的信息就行了。
原理是这样的代码可能有点错误,没有验证。