我正在制作一个C#应用程序,它用阿迪诺-克莱编译Arduino代码。我用流程类调用它,使用ProcessStartInfo类,当然通过cmd.exe调用,这是绝对必要的。
arduino-cli.exe忽略所有参数,并在直接启动它时输出以下两行5秒,而不是通过cmd.exe或在PowerShell控制台中运行:
这是一个命令行工具。 您需要打开cmd.exe并从那里运行它。
我可以选择具有正确路径的目录,但是当我选择要编译的另一个目录时,arduino-cli.exe会输出错误消息:
错误:"arduino-cli“的未知命令"Studio”
我认为这是因为我选择的目录位于一个名为Visual Studio Projects的文件夹中,其中包含名称中的空格,我认为它将每个单词解释为单独的参数。
如何对通过cmd.exe传递给arduino-cli.exe的参数进行编码,以便将两个文件名(输入文件名和十六进制文件)包含在完整限定文件名中的空格作为完整的参数字符串?
我在网上读到,如果我在路径之前添加@,它应该修复它,但是它没有做太多事情。
当我直接在arduino-cli命令提示符窗口中运行C#命令行时,除了C#之外,也会发生这种情况。这个问题可能与命令行语法有关。
以下是我的C#代码:
ProcessStartInfo cmd = new ProcessStartInfo();
cmd.FileName = "cmd.exe";
cmd.WindowStyle = ProcessWindowStyle.Normal;
hexFile = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) + "\\cache/a";
cmd.Arguments = "/k cd " + Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) + "\\avr-g++\\arduino-cli\\bin"
+ " & arduino-cli --compile " + @inFile + " --output " + @hexFile + " multi";
//file = hexFile;
Process.Start(cmd);发布于 2021-02-06 17:56:43
问题是这条路太长了,它需要一条"“围绕着这条路。现在的代码就是这样-
ProcessStartInfo cmd = new ProcessStartInfo();
cmd.FileName = "cmd.exe";
cmd.WindowStyle = ProcessWindowStyle.Normal;
string name = GenerateName(8);
hexFile = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) + "\\cache/" + name;
cmd.Arguments = "/k cd " + Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) + "\\avr-g++\\arduino-cli\\bin"
+ " & arduino-cli compile -b arduino:avr:uno " + "\"" + @inFile + "\"" + " --build-path " + "\"" + @hexFile + "\"";
file = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) + "\\cache\\" + name + "\\" + Path.GetFileName(inFile) + ".hex";
Process.Start(cmd);
Thread.Sleep(3000);
``https://stackoverflow.com/questions/66058143
复制相似问题