How to bind own file extension to python script with console suppressed

738 views Asked by At

First of all, sorry for my english.

I have created my own file extension and bound it to my python script with assoc and ftype:

assoc .iv=IV.Measurement
ftype IV.Measurement=python /path/to/my/script/myscript.py %1

It works like a charm.
But if I want to suppress the console it shows me a dialog to select default app to open my file and proposes python.exe as default.
If I try:

ftype IV.Measurement=python /path/to/my/script/myscript.pyw %1

it works and shows me console.
If I try:

ftype IV.Measurement=pythonw /path/to/my/script/myscript.py %1

or

ftype IV.Measurement=pythonw /path/to/my/script/myscript.pyw %1

it makes me choose default app.

And if I choose pythonw.exe as default it try to run my file as pythonw app bypassing my script, like this:

pythonw my_iv_file.iv

In spite of this I can to run my app from cmd:

pythonw /path/to/my/script/myscript.pyw my_iv_file.iv

How can I bind my file extension to pythonw? Thanks.

1

There are 1 answers

0
martineau On BEST ANSWER

I was able to get it to work without displaying a console using these commands to associate the file type with the script:

assoc .iv=IV.Measurement
ftype IV.Measurement=C:\Python27\pythonw.exe "C:\Test Files\myscript.pyw" %1 %*

The main things to note are I used a full paths to bothpythonw.exeas well as to myscript.pyw, plus backslashes ("\") were used as path separator characters. You'll also need to enclose any paths in double quotes if they contain any space characters.

Afterwards whenmy_iv_file.ivwas double-clicked to open, the value ofsys.argvin myscript.pywwas:

["C:\Test Files\myscript.pyw", "C:\Test Files\my_iv_file.iv"]