C#procss.startinfo.arguments这个参数要怎么设置?非常急希望高手帮忙

zilongzhyu 2008-03-10 03:14:22
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName =
startInfo.Arguments =
System.Diagnostics.Process.Start(startInfo);

要调用一个压缩程序叫lz77.exe位置在D:\学习\benben\benben\src\lz77\Debug在CMD中运行的时候参数是
c sourcefile destfile (比如 在CMD进入当前目录后输入lz77.exe c d:\1.txt d:\2.rar可以生成一个2.rar)
我现在想在C#中调用这个程序,请问Name和Arguments要怎么设置才行啊,网上找过很多还是不会。
...全文
4803 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
venus_dong 2012-02-14
  • 打赏
  • 举报
回复
是不好,到底怎么解决的也没有共享出来,让我们这些后来的还得再思考一次。
  • 打赏
  • 举报
回复
唉!人家写了这么多,都没有给别人结贴的,可叹!可悲!可想而知.......
whitechololate 2008-11-13
  • 打赏
  • 举报
回复
收藏了!~ 学习
zilongzhyu 2008-03-11
  • 打赏
  • 举报
回复
哈哈搞定了,开窍了LS的那些加号跟引号使我开窍了,谢谢啦分数给你吧
zilongzhyu 2008-03-11
  • 打赏
  • 举报
回复
不行啊,我现在把c sourcefile destfile这个参数里的sourcefile放在textBox1.Text
destfile放在textBox3.Text里,然后那2个直这样设还是不行啊
startInfo.FileName = @"D:\学习\benben\benben\src\lz77\Debug"+"\\lz77.exe";
startInfo.Arguments = " c textBox1.Text textBox3.Text";

上面那位说的p.StartInfo.Arguments="x -p"+pwd+" "+SourStr+" "+DestStr
里的 x -p是什么意思啊,还有引号为什么加在那些位置
lyq198345 2008-03-11
  • 打赏
  • 举报
回复
这个问题其实不难,C#的参数,一般可以用Environment.GetCommandLineArgs()获得。
下面给个例子给你。
testOpenFormWithArg这个Form,用来被调用的。
以下是Program.cs的代码
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace testOpenFormWithArg
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string[] str = Environment.GetCommandLineArgs();
Application.Run(new Form1(str[1]));
}
}
}
以下是testOpenFormWithArg的Form中的代码:
using System.Windows.Forms;

namespace testOpenFormWithArg
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public Form1(string argString)
{
InitializeComponent();
MessageBox.Show(argString);
}
}
}

好了 被调用程序写好了 编译好了把exe复制到要调用的文件夹 我这里直接复制到OpenAppWithArg的Debug里,
OpenAppWithArg就是你需要的项目。窗体上面有2个label 2个textBox用来放要打开的文件名(txtExeName),和参数(txtArgName)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace OpenAppWithArg
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.button1.Text = "Open a *.exe file with argMent";
}

private void button1_Click(object sender, EventArgs e)
{
string exeName = this.txtExeName.Text.Trim();
string argName = txtArgName.Text.Trim();
ProcessStartInfo prcess = new ProcessStartInfo(exeName, argName);
prcess.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(prcess);
}

}
}

最后运行OpenAppWithArg程序。在文件名输入testOpenFormWithArg.exe,在参数输入“hello world!”,
那么testOpenFormWithArg文件被执行,并且弹出消息对话框“hello world!”;
ericzhangbo1982111 2008-03-11
  • 打赏
  • 举报
回复
不可能阿 代码我看看
zilongzhyu 2008-03-11
  • 打赏
  • 举报
回复
谢LS的我继续顶~
zilongzhyu 2008-03-11
  • 打赏
  • 举报
回复
我去试试行不行
wenyu1973 2008-03-11
  • 打赏
  • 举报
回复
System.Diagnostics.Process p=new System.Diagnostics.Process();

p.StartInfo.FileName=System.Windows.Forms.Application.StartupPath+"\\Rar.exe";//需要启动的程序名

//p.StartInfo.Arguments="x d:\\a.rar c:\\";

p.StartInfo.Arguments="x -p"+pwd+" "+SourStr+" "+DestStr;

p.Start();
goldxinx 2008-03-11
  • 打赏
  • 举报
回复
帮顶~~!
zilongzhyu 2008-03-11
  • 打赏
  • 举报
回复
LS是VB的啊,那两个值跟我题目也不一样啊
sdyqingdao 2008-03-11
  • 打赏
  • 举报
回复
Dim ProcessStartInfo As New System.Diagnostics.ProcessStartInfo()
ProcessStartInfo.FileName = "iexplore.exe"
ProcessStartInfo.Arguments = "http://www.faqts.com"
ProcessStartInfo.WorkingDirectory = ""
ProcessStartInfo.WindowStyle = ProcessStartInfo.WindowStyle.Maximized
ProcessStartInfo.UseShellExecute = True
ProcessStartInfo.CreateNoWindow = False
System.Diagnostics.Process.Start(ProcessStartInfo)
zilongzhyu 2008-03-11
  • 打赏
  • 举报
回复
我这个参数是一个字母和两个文件路径,你说的方法好象不能用啊,还有我这个程序主要功能不是为了调用程序是解压文件,运行时还让别人输参数那太行了
zilongzhyu 2008-03-11
  • 打赏
  • 举报
回复
写了这么多先谢了,我等下在去研究研究
zilongzhyu 2008-03-11
  • 打赏
  • 举报
回复
写了这么多先谢了,我等下在去研究研究
zilongzhyu 2008-03-10
  • 打赏
  • 举报
回复
顶啊大家踊跃发言啊
zilongzhyu 2008-03-10
  • 打赏
  • 举报
回复
睡觉前在顶一下~
zilongzhyu 2008-03-10
  • 打赏
  • 举报
回复
顶啊,大家帮忙啊,谢谢~~~
zilongzhyu 2008-03-10
  • 打赏
  • 举报
回复
没用啊我试过了不行啊~~~555好痛苦啊两天了还没搞定这个
加载更多回复(2)

110,534

社区成员

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

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

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