带参数的命令行
我有这段代码:
string filePath = ConfigurationManager.AppSettings.Get("FILE_SAVE_PATH") + fileName;
string newFilePath = ConfigurationManager.AppSettings.Get("FILE_SAVE_PATH") + fileName.Replace(".dbf", ".csv");
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory = ConfigurationManager.AppSettings.Get("FILE_SAVE_PATH");
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format("\"{0}\" \"{1}\" /EXPORT:{2} /SEPTAB", ConfigurationManager.AppSettings.Get("DBF_VIEWER_PATH"), filePath, newFilePath);
try
{
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch{}
问题是,它启动命令行,但什么也不做。它似乎没有将参数传递给命令行(命令行为空)。有人知道问题可能出在哪里吗?
i have this code:
string filePath = ConfigurationManager.AppSettings.Get("FILE_SAVE_PATH") + fileName;
string newFilePath = ConfigurationManager.AppSettings.Get("FILE_SAVE_PATH") + fileName.Replace(".dbf", ".csv");
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory = ConfigurationManager.AppSettings.Get("FILE_SAVE_PATH");
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format("\"{0}\" \"{1}\" /EXPORT:{2} /SEPTAB", ConfigurationManager.AppSettings.Get("DBF_VIEWER_PATH"), filePath, newFilePath);
try
{
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch{}
The problem is, that it starts command line, and does nothing. It seems that it does not pass arguments to command line (command line is empty). Anybody has an idea where the problem could be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我解决了我的问题。它就在我体内。我试图启动命令行并为其提供参数,因此它会启动另一个带有参数的程序。这不是很蠢吗?
现在我用参数启动我需要的程序,它运行得很好:
I resolved my problem. It was in me. I was trying to launch command line and give parameters to it, so it would launch another program with parameters. Isn't that stupid?
Now i launch the program i need with parameters and it works perfectly:
您可以尝试将
/c
(执行命令然后终止
)参数添加到 cmd.exe:编辑:正如 Pedro 指出的,您确实应该避免
catch{ }
因为它将隐藏任何抛出的异常。You could try to add
/c
(Carries out command and then terminates
) argument to cmd.exe:EDIT: As Pedro noted, you really should avoid
catch{}
as it will hide any thrown exception.像这样使用 catch:
这样就会显示发生的异常,并为您提供有关错误的重要信息。
Use catch like this:
so the occured exception will be displayed and will give you crucial informations about what is wrong.