带参数的命令行 [英] Command line with parameters

查看:159
本文介绍了带参数的命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

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?

推荐答案

我解决了我的问题。这是在我。我试图启动命令行并给它的参数,所以它会启动另一个程序的参数。是不是很蠢?
现在我启动程序我需要参数,它的工作原理:

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:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory = ConfigurationManager.AppSettings.Get("FILE_SAVE_PATH");
startInfo.FileName = ConfigurationManager.AppSettings.Get("DBF_VIEWER_PATH");
startInfo.Arguments = string.Format("\"{0}\" /EXPORT:{1} /SEPTAB", filePath, newFilePath);
using (Process exeProcess = Process.Start(startInfo))
{
    exeProcess.WaitForExit();
}

这篇关于带参数的命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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