subprocess.open throws error spawn ./jre/bin/java ENOENT exception
import subprocess
subprocess.run([r"C:\Users\<user>\AppData\Local\Programs\<some_dir>\<some_tool>.exe", "--args", "--remote-debugging-port=9000"])
Also tried,
subprocess.Popen([r"C:\Users\<user>\AppData\Local\Programs\<some_dir>\<some_tool>.exe", "--args", "--remote-debugging-port=9000"])
Also tried shell=True
param in Popen but didn't solve
Manual launch of this app is not causing any issue.
Not sure what is causing this issue - How can I fix the same?
When i run this from command there is similar that appears in console output but no blocking dialog appears and application does not crash - Is there any way i can
replicate the NOT-crashing behavior from python as well.
Following is the command line output:
c:\Users\<user>\AppData\Local\Programs\<base_dir>>
18:56:05.542 > Start in production mode
18:56:05.585 > electron-log.transports.file: Can't write to c:\Users\<user>\AppData\Local\Programs\<base_dir>\resources\app.asar\logs\main.log Error: ENOTDIR, not a directory
at createError (electron/js2c/asar_bundle.js:5:1382)
at Object.e.mkdirSync (electron/js2c/asar_bundle.js:5:12161)
at e (c:\Users\<user>\AppData\Local\Programs\<base_dir>\resources\app.asar\background.js:1:249748)
at l.testFileWriting (c:\Users\<user>\AppData\Local\Programs\<base_dir>\resources\app.asar\background.js:1:249938)
at l.createFile (c:\Users\<user>\AppData\Local\Programs\<base_dir>\resources\app.asar\background.js:1:249488)
at l.provide (c:\Users\<user>\AppData\Local\Programs\<base_dir>\resources\app.asar\background.js:1:249315)
at d (c:\Users\<user>\AppData\Local\Programs\<base_dir>\resources\app.asar\background.js:1:246666)
at h (c:\Users\<user>\AppData\Local\Programs\<base_dir>\resources\app.asar\background.js:1:246165)
at i (c:\Users\<user>\AppData\Local\Programs\<base_dir>\resources\app.asar\background.js:1:47829)
at n (c:\Users\<user>\AppData\Local\Programs\<base_dir>\resources\app.asar\background.js:1:47621)
18:56:05.606 > Launching server at backend\<application>-backend-0.0.1-SNAPSHOT.jar at port 8885...
18:56:05.724 > Server PID: 69044
18:56:10.731 >
18:56:10.733 > . ____ _ __ _ _
18:56:10.737 > /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
18:56:10.739 > ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
18:56:10.740 > \\/ ___)| |_)| | | | | || (_| | ) ) ) )
18:56:10.741 > ' |____| .__|_| |_|_| |_\__, | / / / /
18:56:10.742 > =========|_|==============|___/=/_/_/_/
18:56:10.744 > :: Spring Boot :: (v2.5.4)
18:56:10.745 >
18:56:11.126 > 2021-12-10 18:56:11.119 INFO 69044 --- [ main] p.core.<application>BackendApplication : Starting <application>BackendApplication using Java 11.0.13 on G1-6FWX7C3-L with PID 69044 (C:\Users\<user>\AppData\Local\Programs\<base_dir>\backend\<application>-backend-0.0.1-SNAPSHOT.jar started by <user> in c:\Users\<user>\AppData\Local\Programs\<base_dir>)
18:56:11.127 > 2021-12-10 18:56:11.126 INFO 69044 --- [ main] p.core.<application>BackendApplication : No active profile set, falling back to default profiles: default
18:56:18.360 > 2021-12-10 18:56:18.359 INFO 69044 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8885 (http)
18:56:18.446 > 2021-12-10 18:56:18.444 INFO 69044 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
18:56:18.447 > 2021-12-10 18:56:18.445 INFO 69044 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.52]
18:56:18.889 > 2021-12-10 18:56:18.887 INFO 69044 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
18:56:18.891 > 2021-12-10 18:56:18.888 INFO 69044 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 7499 ms
18:56:23.934 > 2021-12-10 18:56:23.933 INFO 69044 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 14 endpoint(s) beneath base path '/rest/actuator'
18:56:24.174 > 2021-12-10 18:56:24.172 INFO 69044 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8885 (http) with context path ''
18:56:24.241 > 2021-12-10 18:56:24.241 INFO 69044 --- [ main] p.core.<application>BackendApplication : Started <application>BackendApplication in 15.385 seconds (JVM running for 17.665)
18:56:24.644 > 2021-12-10 18:56:24.642 INFO 69044 --- [nio-8885-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
18:56:24.645 > 2021-12-10 18:56:24.643 INFO 69044 --- [nio-8885-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
18:56:24.657 > 2021-12-10 18:56:24.647 INFO 69044 --- [nio-8885-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 4 ms
Ok - so Electron Package was bundled with its own jre
version which was causing the issue as invoking the exe
was causing the JAVA dependencies to be looked up at system default jre
path instead of the one bundled with the Electron application.
Solution - switch to base directory of application and then launch it:
import subprocess, os
from subprocess import *
os.chdir(r"C:\app_dir")
subprocess.Popen(['app.exe'])
Hope this helps someone facing similar issue.