Page 1 of 1

[Windows] Suppress CMD window

Posted: 27 Jun 2017, 10:17
by rednoah
Background:

Windows executables come in two flavours. GUI executables and CLI executables. Windows will always pop up a new CMD windows when a CLI executable is invoked by a GUI executable. This behaviour is especially annoying for background jobs.


The Quick & Dirty Solution:

Running command-line tools without a CMD window on Windows is tricky. The quick and dirty solution is to call CMD minimized using the following trick:

Code: Select all

cmd /c START /MIN cmd /c filebot -script fn:amc ...
:idea: ... refers to the rest of the amc script command-line template. The first cmd /c call (that just spawns another minimized CMD) will still pop up a CMD window, but only for a short amount of time, so it won't steal the focus if you're lucky.



Instructions for µTorrent:

We can use pythonw to call python scripts in the background and then call filebot from there. Calling filebot from python instead of µTorrent also makes it easier to pass in custom options or perform custom operations before or after the amc script is called.

  1. Install Python and restart your computer. Call python --version to make sure that python is installed correctly and in the $PATH. Please use Python 3 or higher.
  2. Fetch (right-click, Save As...) the utorrent-postprocess.pyw python script and modify (open with Notepad++ and edit) it to your needs:

    Code: Select all

    # configuration
    output = 'X:/Media'
  3. Set Run Program to your script and pass in all the µTorrent variables via command-line arguments:

    Code: Select all

    "C:\path\to\utorrent-postprocess.pyw" "%L" "%S" "%N" "%K" "%F" "%D"
    Note: pyw files are executed with pythonw.exe which is a GUI executable and so it won't pop up a CMD window.


Instructions for qBittorrent:

Same as the above, except that we call utorrent-postprocess.pyw with the appropriate qBittorrent variables:

Code: Select all

"C:\path\to\utorrent-postprocess.pyw" "%L" "" "%N" "multi" "" "%F"

Re: [Windows] Suppress CMD window

Posted: 31 Mar 2018, 10:10
by ZeroByDivide
Just an update, but upon release of qBittorrent 4.0.5 and above the command for "Run external program on torrent completion" will have to be changed from

Code: Select all

"C:\path\to\utorrent-postprocess.pyw" "%L" "" "%N" "multi" "" "%F"
to

Code: Select all

"C:\path\to\pythonw.exe" "C:\path\to\utorrent-postprocess.pyw" "%L" "" "%N" "multi" "" "%F"
as qbittorrent team have reverted "Run external program on torrent completion" back to square one (noted here https://github.com/qbittorrent/qBittorr ... -377679108) so qBittorrent will no longer be able to access anything in

Code: Select all

%path%
which also means that this post needs to be edited as well viewtopic.php?f=4&t=215#p9774

Re: [Windows] Suppress CMD window

Posted: 12 Apr 2018, 18:44
by eway
Is there a more detaild guide of how to do all this step by step? seems complicated to me what am i refrencing here: "C:\path\to\python.pyw"

Re: [Windows] Suppress CMD window

Posted: 12 Apr 2018, 20:09
by rednoah
rednoah wrote:The Quick & Dirty Solution:

Running command-line tools without a CMD window on Windows is tricky. The quick and dirty solution is to call CMD minimized using the following trick:

Code: Select all

cmd /c START /MIN cmd /c filebot -script fn:amc ...
:idea: ... refers to the rest of the amc script command-line template. The first cmd /c call (that just spawns another minimized CMD) will still pop up a CMD window, but only for a short amount of time, so it won't steal the focus if you're lucky.
Have you tried this?

Re: [Windows] Suppress CMD window

Posted: 12 Apr 2018, 20:26
by eway
Yes that works, thats what i am running today, but i would like to try the other solution seems more elegant...

The real Problem is that i do not understand the underlying function of how the script works, hehe .

Is the script built in to the filebot program?

Re: [Windows] Suppress CMD window

Posted: 13 Apr 2018, 02:51
by rednoah
pythonw and utorrent-postprocess.pyw have nothing to do with filebot. The latter just happens to call filebot but it could also call any other tool or program.

Re: [Windows] Suppress CMD window

Posted: 05 May 2018, 22:01
by ZeroByDivide
ZeroByDivide wrote: 31 Mar 2018, 10:10 Just an update, but upon release of qBittorrent 4.0.5 and above the command for "Run external program on torrent completion" will have to be changed from

Code: Select all

"C:\path\to\utorrent-postprocess.pyw" "%L" "" "%N" "multi" "" "%F"
to

Code: Select all

"C:\path\to\pythonw.exe" "C:\path\to\utorrent-postprocess.pyw" "%L" "" "%N" "multi" "" "%F"
as qbittorrent team have reverted "Run external program on torrent completion" back to square one (noted here https://github.com/qbittorrent/qBittorr ... -377679108) so qBittorrent will no longer be able to access anything in

Code: Select all

%path%
which also means that this post needs to be edited as well viewtopic.php?f=4&t=215#p9774
Just to note: Qbittorrent has released 4.1.0 (they went straight from 4.0.4 to 4.1.0) so the above quote is now in affect for anyone who is running qbittorrent 4.1.0 and newer releases in the future.

Re: [Windows] Suppress CMD window

Posted: 10 May 2018, 08:09
by illusionist

Code: Select all

"C:\path\to\python.pyw" "C:\path\to\utorrent-postprocess.pyw" "%L" "" "%N" "multi" "" "%F"
After replacing values, would this be?

Code: Select all

"C:\Python36\pythonw.exe" "C:\Python36\Scripts\utorrent-postprocess.pyw" "%L" "" "%N" "multi" "" "%F"
(Assuming Python 3.6 is installed in C:\ and utorrent-postprocess.pyw is placed in C:\Python36\Scripts)

Just confirming.

Re: [Windows] Suppress CMD window

Posted: 10 May 2018, 09:36
by ZeroByDivide
illusionist wrote: 10 May 2018, 08:09

Code: Select all

"C:\path\to\python.pyw" "C:\path\to\utorrent-postprocess.pyw" "%L" "" "%N" "multi" "" "%F"
After replacing values, would this be?

Code: Select all

"C:\Python36\pythonw.exe" "C:\Python36\Scripts\utorrent-postprocess.pyw" "%L" "" "%N" "multi" "" "%F"
(Assuming Python 3.6 is installed in C:\ and utorrent-postprocess.pyw is placed in C:\Python36\Scripts)

Just confirming.
if you are using qbittorrent then yes that would be the correct stuff if you where to assume those paths.

Re: [Windows] Suppress CMD window

Posted: 31 May 2018, 04:40
by cmre222333
Im so confused. Iv had filebot or AMC working great in the past. Now i just cant get it to work . can some one make an easy tutorial with examples or video tutorial? The old forum post in here are out of date and very vague. I just payed for filebot just for Amc . It was free when i had it working 1 year ago . Thank you to any one that can help me .

Re: [Windows] Suppress CMD window

Posted: 31 May 2018, 07:41
by rednoah
Please make a new thread and describe what you're doing so far and what's not working and what you have tried so far to figure out what's not working.

This thread is for advanced users that want to suppress the CMD window, but otherwise have a good grasp on how the amc script works and how to set it up. The first step is to follow the amc script manual, and once everything is working, you can follow up on advanced tutorials to make things work exactly the way you want.

Re: [Windows] Suppress CMD window

Posted: 22 Oct 2018, 20:05
by rspierenburg
Hi, I'm looking to use the uttorent-postprocess.pyw file with a few tweaks. I'de like to add an -def ignore and -def kodi to it but I'm not sure where. My first thought was to place them at the end of the Command = [...] block but it seemed to stop filebot from running at all.

Re: [Windows] Suppress CMD window

Posted: 23 Oct 2018, 04:11
by rednoah
Make sure that the script is syntactically correct after making your modifications. You can see the console output by running the script with python instead of pythonw. The console output will tell us exactly what's wrong with your script and why it doesn't work.

Re: [Windows] Suppress CMD window

Posted: 28 Dec 2018, 06:02
by RedSteelMoss
Hello! I'm using the python script to call filebot. I'd just like to make a suggestion that you say in the post or in the script itself that if you're using regex in the custom formats you need to double the amount of backslashes. So \b would have to be \\b and \w would have to be \\w etc.

Re: [Windows] Suppress CMD window

Posted: 28 Dec 2018, 06:51
by rednoah
Best to use @files so you don't have to worry about any of these language specific things:
viewtopic.php?f=4&t=3244