0

I am trying to open a java link I have saved on my folder on my desktop. I can't get it to find the file. The java address is x:\green\Adam\FILEJAR.jar. This is an executable JAR file I want to open it and have it on my desktop, just open it and have it run as normal for the Java link. Want Python just to open it.

import subprocess
run="x:\green\Adam\FILEJAR.jar"
proc=subprocess.Popen(run)

I get this....

Traceback (most recent call last):
File "C:/Python32/test3", line 3, in <module>
proc=subprocess.Popen(run)
File "C:\Python32\lib\subprocess.py", line 741, in __init__
restore_signals, start_new_session)
File "C:\Python32\lib\subprocess.py", line 960, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

What am I doing wrong, why can't it find the file?

3

1 Answer 1

1

The jar file itself is nothing but an archive with byte-compiled java code. To execute it properly, try:

import subprocess
run = r"java -jar x:\green\Adam\FILEJAR.jar"
proc = subprocess.Popen(run)
5
  • 2
    Won't work. Eiter add a , shell=True to the Popen() call, or set run = ['java', '-jar', r'x:\reen\Adam\FILEJAR.jar'].
    – glglgl
    Commented Nov 14, 2011 at 10:40
  • I run it with no errors but it isn't visible, tried proc.Visible =True, nothing??? can I make it visible? Commented Nov 14, 2011 at 10:57
  • Still can't get the java script to become a visible screen kinda stuck on it Commented Nov 21, 2011 at 7:37
  • If you run the Jar normally does it open the UI? Commented Feb 16 at 16:14
  • I assume by "running Jar normally" you mean "double-clicking it in some Windows explorer", or something similar? A JAR file is an archive which contains a compiled Java program along the program resources. However, it's not a self-contained executable from operating system's perspective, you need a Java Virtual Machine to run it. Operating System tools like "File Explorer" can be aware about this all, and simply call "java -jar ..." under the hood, when you are trying to "run" it. Commented Feb 23 at 12:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.