Skip to content

Commit b97f756

Browse files
committed
Bugfixes
Changed sysExec() to be based on: https://www.infoworld.com/article/2071275/when-runtime-exec---won-t.html The original way hangs on long uploading.
1 parent e4c702f commit b97f756

File tree

3 files changed

+61
-41
lines changed

3 files changed

+61
-41
lines changed

Diff for: src/ESP32FS.java

+59-39
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@
2323

2424
package com.esp32.mkspiffs;
2525

26-
import java.io.File;
27-
import java.io.FileReader;
28-
import java.io.BufferedReader;
29-
import java.io.InputStreamReader;
30-
import java.io.IOException;
26+
import java.util.*;
27+
import java.io.*;
3128

3229
import java.text.SimpleDateFormat;
33-
import java.util.Date;
3430
import java.lang.reflect.Field;
3531
import java.lang.reflect.InvocationTargetException;
3632
import javax.swing.JOptionPane;
@@ -51,6 +47,32 @@
5147

5248
import cc.arduino.files.DeleteFilesOnShutdown;
5349

50+
/**
51+
* Taken from https://www.infoworld.com/article/2071275/when-runtime-exec---won-t.html?page=3
52+
*/
53+
class StreamGobbler extends Thread {
54+
InputStream is;
55+
String type;
56+
57+
StreamGobbler(InputStream is, String type) {
58+
this.is = is;
59+
this.type = type;
60+
}
61+
62+
public void run() {
63+
try {
64+
InputStreamReader isr = new InputStreamReader(is);
65+
BufferedReader br = new BufferedReader(isr);
66+
String line=null;
67+
while ( (line = br.readLine()) != null)
68+
System.out.println(type + ">" + line);
69+
} catch (IOException ioe) {
70+
ioe.printStackTrace();
71+
}
72+
}
73+
}
74+
75+
5476
/**
5577
* Example Tools menu entry.
5678
*/
@@ -71,31 +93,26 @@ public String getMenuTitle() {
7193

7294
private int listenOnProcess(String[] arguments){
7395
try {
74-
final Process p = ProcessUtils.exec(arguments);
75-
Thread thread = new Thread() {
76-
public void run() {
77-
try {
78-
InputStreamReader reader = new InputStreamReader(p.getInputStream());
79-
int c;
80-
while ((c = reader.read()) != -1)
81-
System.out.print((char) c);
82-
reader.close();
83-
84-
reader = new InputStreamReader(p.getErrorStream());
85-
while ((c = reader.read()) != -1)
86-
System.err.print((char) c);
87-
reader.close();
88-
} catch (Exception e){}
89-
}
90-
};
91-
thread.start();
92-
int res = p.waitFor();
93-
thread.join();
94-
return res;
96+
Runtime rt = Runtime.getRuntime();
97+
Process proc = rt.exec(arguments);
98+
// any error message?
99+
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "E");
100+
101+
// any output?
102+
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "O");
103+
104+
// kick them off
105+
errorGobbler.start();
106+
outputGobbler.start();
107+
108+
// any error???
109+
int exitVal = proc.waitFor();
110+
111+
return exitVal;
95112
} catch (Exception e){
96113
return -1;
97114
}
98-
}
115+
}
99116

100117
private void sysExec(final String[] arguments){
101118
Thread thread = new Thread() {
@@ -328,9 +345,12 @@ private void createAndUpload(){
328345
isNetwork = true;
329346
espota = new File(platform.getFolder()+"/tools", espotaCmd);
330347
if(!espota.exists() || !espota.isFile()){
331-
System.err.println();
332-
editor.statusError(typefs + " Error: espota not found!");
333-
return;
348+
espota = new File(platform.getFolder()+"/tools", "espota.py"); //fall-back to .py
349+
if(!espota.exists() || !espota.isFile()){
350+
System.err.println();
351+
editor.statusError(typefs + " Error: espota not found!");
352+
return;
353+
}
334354
}
335355
System.out.println("espota : "+espota.getAbsolutePath());
336356
System.out.println();
@@ -354,11 +374,10 @@ private void createAndUpload(){
354374
}
355375
}
356376
}
377+
System.out.println("esptool : "+esptool.getAbsolutePath());
378+
System.out.println();
357379
}
358-
System.out.println("esptool : "+esptool.getAbsolutePath());
359-
System.out.println();
360-
361-
380+
362381
//load a list of all files
363382
int fileCount = 0;
364383
File dataFolder = new File(editor.getSketch().getFolder(), "data");
@@ -426,9 +445,10 @@ private void createAndUpload(){
426445

427446
if(isNetwork){
428447
System.out.println("[" + typefs + "] IP : "+serialPort);
429-
System.out.println();
448+
System.out.println("Running: " + espota.getAbsolutePath() + " -i " + serialPort + " -p 3232 -s -f " + imagePath);
449+
System.out.println();
430450
if(espota.getAbsolutePath().endsWith(".py"))
431-
sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-p", "3232", "-s", "-f", imagePath});
451+
sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-p", "3232", "-s", "-f", imagePath}); // other flags , "-d", "-r", "-t", "50"
432452
else
433453
sysExec(new String[]{espota.getAbsolutePath(), "-i", serialPort, "-p", "3232", "-s", "-f", imagePath});
434454
} else {
@@ -507,9 +527,9 @@ private void eraseFlash(){
507527
}
508528
}
509529
}
530+
System.out.println("esptool : "+esptool.getAbsolutePath());
531+
System.out.println();
510532
}
511-
System.out.println("esptool : "+esptool.getAbsolutePath());
512-
System.out.println();
513533

514534
Object[] options = { "Yes", "No" };
515535
String title = "Erase All Flash";

Diff for: src/bin/placeholder

Whitespace-only changes.

Diff for: src/make_win.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
del bin\*.jar
22
rd /S /Q bin\com
3-
"C:\Program Files (x86)\Java\jdk1.8.0_152\bin\javac.exe" -target 1.8 -cp ".;arduino-core.jar;commons-codec-1.7.jar;pde.jar" -d bin ESP32FS.java
3+
javac.exe -target 1.8 -cp ".;arduino-core.jar;commons-codec-1.7.jar;pde.jar" -d bin ESP32FS.java
44
cd bin
5-
"C:\Program Files (x86)\Java\jdk1.8.0_152\bin\jar.exe" cvfM esp32fs.jar *
5+
jar.exe cvfM esp32fs.jar *
66
pause

0 commit comments

Comments
 (0)