Executing .exe using the QProcess issue
-
Hello. I am learning about QProcess and would like to execute some .exe file to flash external microcontroller (ESP32) via my QT application.
If I open Command Promt, I can execute the following command to flash the external device:
C:\Users\petrikas.lu\Desktop\WORK\QT\UTB\UTB_gui>tools\esptool.exe --p COM73 -b 460800 --chip esp32 write_flash 0x1000 bins\bootloader.bin 0x8000 bins\partition-table.bin 0xd000 bins\ota_data_initial.bin 0xf000 bins\phy_init_data.bin 0x10000 bins\ELSTAT_ESP_IDF.bin 0x4f0000 bins\storage.bin
And my microcontroller will be flashed without any issues, the command prompt output when I execute the command:
C:\Users\petrikas.lu\Desktop\WORK\QT\UTB\UTB_gui>tools\esptool.exe --p COM73 -b 460800 --chip esp32 write_flash 0x1000 bins\bootloader.bin 0x8000 bins\partition-table.bin 0xd000 bins\ota_data_initial.bin 0xf000 bins\phy_init_data.bin 0x10000 bins\ELSTAT_ESP_IDF.bin 0x4f0000 bins\storage.bin esptool.py v4.1-dev Serial port COM73 Connecting......... Chip is ESP32-D0WD-V3 (revision 3) Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None Crystal is 40MHz MAC: 8c:4b:14:10:28:94 Uploading stub... Running stub... Stub running... Changing baud rate to 460800 Changed. Configuring flash size... Flash will be erased from 0x00001000 to 0x00007fff... Flash will be erased from 0x00008000 to 0x00008fff... Flash will be erased from 0x0000d000 to 0x0000efff... Flash will be erased from 0x0000f000 to 0x0000ffff... Flash will be erased from 0x00010000 to 0x00176fff... Flash will be erased from 0x004f0000 to 0x0068ffff... Compressed 25296 bytes to 15799... Wrote 25296 bytes (15799 compressed) at 0x00001000 in 0.8 seconds (effective 242.6 kbit/s)... Hash of data verified. Compressed 3072 bytes to 159... Wrote 3072 bytes (159 compressed) at 0x00008000 in 0.1 seconds (effective 323.4 kbit/s)... Hash of data verified. Compressed 8192 bytes to 31... Wrote 8192 bytes (31 compressed) at 0x0000d000 in 0.1 seconds (effective 445.1 kbit/s)... Hash of data verified. Compressed 144 bytes to 69... Wrote 144 bytes (69 compressed) at 0x0000f000 in 0.1 seconds (effective 16.2 kbit/s)... Hash of data verified. Compressed 1469520 bytes to 916923... Wrote 1469520 bytes (916923 compressed) at 0x00010000 in 22.8 seconds (effective 514.8 kbit/s)... Hash of data verified. Compressed 1703936 bytes to 3171... Wrote 1703936 bytes (3171 compressed) at 0x004f0000 in 8.5 seconds (effective 1612.2 kbit/s)... Hash of data verified. Leaving... Hard resetting via RTS pin...
Now I try to do exact same thing in my QT
In my working directory (C:\Users\petrikas.lu\Desktop\WORK\QT\UTB\UTB_gui):
-
I have tools folder which contain esptool.exe that I want to execute
-
I also have bins folder which contain all binary files that are passed as arguments to the command
QStringList arguments; QProcess process; arguments <<"-p" <<"COM73"; //SELECT COM PORT arguments <<"-b" <<"460800"; //SELECT BAUDRATE arguments <<"--chip" <<"esp32"; //SELECT CHIP2. arguments <<"write_flash"; //SELECT COMMAND arguments <<"0x8000" <<"bins\\partition_table.bin"; //SELECT PARTITION TABLE BIN arguments <<"0xd000" <<"bins\\ota_data_initial.bin";//SELECT OTA DATA INITIAL BIN arguments <<"0xf000" <<"bins\\phy_init_data.bin"; //SELECT PHY INIT DATA BIN arguments <<"0x10000" <<"bins\\ELSTAT_ESP_IDF.bin"; //SELECT MAIN PROGRAM BIN arguments <<"0x4f0000" <<"bins\\storage.bin"; //SELECT STORAGE BIN process.setArguments(arguments); process.setProgram("tools\\esptool.exe"); qDebug() << process.program() << " " << process.arguments(); process.start(); //PRINT OUT THE PROGRAM AND ARGUMENTS if (!process.waitForStarted()){ qDebug() << "Failed to start"; return; } //process.write("..."); //process.closeWriteChannel(); while (process.state() != QProcess::NotRunning) { qDebug() << "."; if (process.waitForReadyRead()) qDebug() << "OUTPUT" << process.readAllStandardOutput(); }
The application output:
"tools\\esptool.exe" QList("-p", "COM73", "-b", "460800", "--chip", "esp32", "write_flash", "0x8000", "bins\\partition_table.bin", "0xd000", "bins\\ota_data_initial.bin", "0xf000", "bins\\phy_init_data.bin", "0x10000", "bins\\ELSTAT_ESP_IDF.bin", "0x4f0000", "bins\\storage.bin") . OUTPUT "" . OUTPUT "" .
I am not fully understanding what could be an issue? Perhaps I have made some syntax error? It is quite strange to me why I am not seeing any output, even if there is some error or issues, I assume I should still see it being printed.
-
-
@lukutis222 First thing to do: add error handling. There are signals and methods in QProcess for that. Also it could be that this tool outputs to stderr instead of stdout.
-
@jsulm
Thank you for suggestion. I updated my code and added std out and std err handling. Now I know what could be the issue:QStringList arguments; QProcess process; //connect(&process, &QProcess::errorOccurred, this, &MainWindow::processError); arguments <<"-p" <<"COM73"; //SELECT COM PORT arguments <<"-b" <<"460800"; //SELECT BAUDRATE arguments <<"--chip" <<"esp32"; //SELECT CHIP2. arguments <<"write_flash"; //SELECT COMMAND arguments <<"0x8000" <<"bins\\partition_table.bin"; //SELECT PARTITION TABLE BIN arguments <<"0xd000" <<"bins\\ota_data_initial.bin";//SELECT OTA DATA INITIAL BIN arguments <<"0xf000" <<"bins\\phy_init_data.bin"; //SELECT PHY INIT DATA BIN arguments <<"0x10000" <<"bins\\ELSTAT_ESP_IDF.bin"; //SELECT MAIN PROGRAM BIN arguments <<"0x4f0000" <<"bins\\storage.bin"; //SELECT STORAGE BIN process.setArguments(arguments); process.setProgram("tools\\esptool.exe"); qDebug() << process.program() << " " << process.arguments(); process.start(); if (process.waitForStarted() && process.waitForFinished()) { qDebug() << "OUTPUT STDO" << process.readAllStandardOutput(); qDebug() << "OUTPUT STDERR" << process.readAllStandardError(); }
Application output:
"tools\\esptool.exe" QList("-p", "COM73", "-b", "460800", "--chip", "esp32", "write_flash", "0x8000", "bins\\partition_table.bin", "0xd000", "bins\\ota_data_initial.bin", "0xf000", "bins\\phy_init_data.bin", "0x10000", "bins\\ELSTAT_ESP_IDF.bin", "0x4f0000", "bins\\storage.bin") OUTPUT STDO "" OUTPUT STDERR "usage: esptool write_flash [-h] [--erase-all]\r\n [--flash_freq {keep,80m,60m,48m,40m,30m,26m,24m,20m,16m,15m,12m}]\r\n [--flash_mode {keep,qio,qout,dio,dout}]\r\n [--flash_size {detect,keep,256KB,512KB,1MB,2MB,2MB-c1,4MB,4MB-c1,8MB,16MB,32MB,64MB,128MB}]\r\n [--spi-connection SPI_CONNECTION] [--no-progress]\r\n [--verify] [--encrypt]\r\n [--encrypt-files <address> <filename> [<address> <filename> ...]]\r\n [--ignore-flash-encryption-efuse-setting] [--force]\r\n [--compress | --no-compress]\r\n <address> <filename> [<address> <filename> ...]\r\nesptool write_flash: error: argument <address> <filename>: [Errno 2] No such file or directory: 'bins\\\\partition_table.bin'\r\n" Failed to start
The last line of the application output says:
No such file or directory: 'bins\\\\partition_table.bin'\r\n"
I do not fully understand why it prints out 4 backslashes and also why does it append \r\n. Is that expected?
-
I have figured out what was an issue. There was a syntax issue:
arguments <<"0x8000" <<"bins\\partition_table.bin"; //SELECT PARTITION TABLE BIN
should be changed to:
arguments <<"0x8000" <<"bins\\partition-table.bin"; //SELECT PARTITION TABLE BIN
Other than that, the program works!
Thank you very much :)