Search code examples
wpfatmel

The command line for 'atprogram' does not work properly in WPF


I am building a WPF application that can flash Atmel MCU. I am using 'atprogram' command line to flash the MCU. Below is the code snippets.

using (Process sortProcess = new Process())
{
    sortProcess.StartInfo.FileName = "cmd.exe";
    string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\Atmel\Studio\7.0\atbackend\atprogram";
    string hexFileName = "PROGRAM.hex";
    string arguments = FormattableString.Invariant($"/K \"{path}\" -t atmelice -i ISP -d atmega328pb program -f \"{hexFileName}\" --verify");
    sortProcess.StartInfo.Arguments = arguments;
    sortProcess.Start();
}

When I run the application, the command lines show:

'C:\Program' is not recognized as an internal or external command,
operable program or batch files.

When I removed '\"{hexFileName}\"' from the program AND also tried to copy and paste the arguments (with double quotes) on Command Prompt, the program works fine (even it gives error). May I know what is the problem?


Solution

  • trying to do this code

            using (Process sortProcess = new Process())
            {
                sortProcess.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\Atmel\Studio\7.0\atbackend\atprogram.exe";
                string hexFileName = "PROGRAM.hex";
                string arguments = FormattableString.Invariant($" -t atmelice -i ISP -d atmega328pb program -f \"{hexFileName}\" --verify");
                sortProcess.StartInfo.Arguments = arguments;
                sortProcess.Start();
            }