将 Windows 命令转换为 Atmel Studio 7 的 C#

Translating a Windows Command into C# for Atmel Studio 7

我一直在尝试 运行 Windows 命令,利用 Atmel Studios atprogram 实用程序,它不完全相关但有助于上下文。

以下是我的代码,想法是将命令的输出推送到富文本框中。这是在 "AddTestJigString(output)" 部分中完成的。

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        string command = cmd();
        Process process = new Process();
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardOutput = true;
        startInfo.FileName = "CMD.exe";
        startInfo.Arguments = "/c cd " + ((char)34) + Path.GetDirectoryName(Properties.Settings.Default.Preferredatprogram) + ((char)34) + " && atprogram.exe - t avrispmk2 - i isp - d ATtiny26 - v chiperase program -f 30 - 5004_U21_V0.7.hex write - fs--values 61F6";
        process.StartInfo = startInfo;
        process.Start();
        string output = process.StandardOutput.ReadToEnd();
        AddTestJigString(output);
        process.WaitForExit();
    }

关键线正在;

    startInfo.Arguments = "/c cd " + ((char)34) + Path.GetDirectoryName(Properties.Settings.Default.Preferredatprogram) + ((char)34) + " && atprogram.exe - t avrispmk2 - i isp - d ATtiny26 - v chiperase program -f 30 - 5004_U21_V0.7.hex write - fs--values 61F6";

如果我将其更改为;

    startInfo.Arguments = "/c cd " + ((char)34) + Path.GetDirectoryName(Properties.Settings.Default.Preferredatprogram) + ((char)34) + " && atprogram.exe";

我从 atprogram.exe 的富文本框中获得了帮助/可用命令列表的输出,所以我做对了。但是,一旦添加任何参数,输出就会完全空白。

感谢以上回复。

作为回应,此命令的参数绝对正确,因为它在生产环境中用作批处理脚本。 问题实际上归结为将命令输出到富文本框 更基​​本地重定向命令输出。

我设法开始使用以下解决方案:

    {
        string comhex = Path.GetFullPath(Properties.Settings.Default.PreferredComHex);
        return "/c atprogram -t avrispmk2 -i isp -d ATtiny26 -v chiperase program -f " + ((char)34) + comhex + ((char)34) + " write -fs --values 61F6 2>&1";
    }

关键部分是我添加到命令字符串末尾的“2>&1”。这有效地告诉命令重定向标准输出 (stdout) 和标准错误 (stderr)。其中 2 个是 stderr,1 个是 stdout。

进一步阅读/参考:

In the shell, what does " 2>&1 " mean?

https://support.microsoft.com/en-gb/help/110930/redirecting-error-messages-from-command-prompt-stderr-stdout