简体   繁体   中英

Python open a JAR shortcut

我有一个JAR文件保存在我的桌面上,是否有一种方法可以让我用python来写这个,好像我只是点击桌面上的链接,我是python的新手,知道这是一个愚蠢的问题,但会帮助我很多。

Why do you want to execute it via Python?

In my Windows environment such .jar file is executed by Java:

C:\jre7\bin\javaw.exe -jar "%1" %*

Of course your OS should be able to change such association to open .jar with other program. On my Windows I can use local menu to open .jar file with Java, Eclipse, Firefox or I can chose other program.

I'll assume you're using Windows (it seems that way from how you've presented the question).

To simulate double-clicking a file on Windows, use os.startfile (available only on Windows):

os.startfile("path/to/myjarfile.jar")

This will do whatever your system is configured to do with files with a .jar extension.

For a more complete answer on starting files on Windows see this answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM