Skip to content

Commit 7c87062

Browse files
committed
Allow for spaces in file path names
1 parent ab1756b commit 7c87062

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/org/deepjava/openOCDInterface/OpenOCD.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,29 @@ public static TargetConnection getInstance() {
4343
public void openConnection() throws TargetConnectionException {
4444
if (dbg) StdStreams.vrb.println("[TARGET] Open connection");
4545
try {
46-
// String currLoc = new File(".").getAbsolutePath();
47-
// currLoc = currLoc.replace(currLoc.substring(currLoc.length()-1), "");
48-
// currLoc += "\\startOpenocd-local.bat";
49-
// String name = "F:\\openocd-0.10.0\\startOpenocdMicrozed.bat";
50-
//// StdStreams.vrb.println("run openocd: " + name);
51-
// File dir = new File("F:\\openocd-0.10.0");
52-
// Process p = Runtime.getRuntime().exec("cmd /c start \"\" " + name, null, dir);
53-
// if (p != null) {
54-
// if (dbg) StdStreams.vrb.println("OpenOCD process not null, " + p.toString());
55-
// } else {
56-
// if (dbg) StdStreams.vrb.println("OpenOCD process null");
57-
// }
58-
5946
socket = new Socket(hostname, port);
6047
socket.setSoTimeout(1000);
6148
out = socket.getOutputStream();
6249
in = socket.getInputStream();
63-
if (dbg) StdStreams.vrb.println("[TARGET] Connected ");
50+
} catch (IOException e) {
51+
if (dbg) StdStreams.vrb.println("[TARGET] no socket connection possible, start OpenOCD");
52+
String currLoc = new File(".").getAbsolutePath();
53+
currLoc = currLoc.replace(currLoc.substring(currLoc.length()-1), "");
54+
currLoc += "\\startOpenocd-local.bat";
55+
String name = "F:\\openocd-0.10.0\\startOpenocdMicrozed.bat";
56+
if (dbg) StdStreams.log.println("run openocd: " + name);
57+
File dir = new File("F:\\openocd-0.10.0");
58+
try {
59+
Runtime.getRuntime().exec("cmd /c start \"\" " + name, null, dir);
60+
socket = new Socket(hostname, port);
61+
socket.setSoTimeout(1000);
62+
out = socket.getOutputStream();
63+
in = socket.getInputStream();
64+
if (dbg) StdStreams.vrb.println("[TARGET] started");
65+
} catch (IOException e1) {
66+
if (dbg) StdStreams.vrb.println("[TARGET] Cannot start OpenOCD server");
67+
throw new TargetConnectionException(e1.getMessage(), e1);
68+
}
6469
} catch (Exception e) {
6570
if (dbg) StdStreams.vrb.println("[TARGET] Connection failed on " + hostname);
6671
throw new TargetConnectionException(e.getMessage(), e);
@@ -142,8 +147,6 @@ public boolean isConnected() {
142147
return false;
143148
}
144149
} catch (IOException e) {
145-
// TODO Auto-generated catch block
146-
// e.printStackTrace();
147150
return false;
148151
}
149152
return (socket.isConnected() && !socket.isClosed());

0 commit comments

Comments
 (0)