[Windows] Suppress CMD window

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

[Windows] Suppress CMD window

Post 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"
:idea: Please read the FAQ and How to Request Help.
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: [Windows] Suppress CMD window

Post 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
Last edited by ZeroByDivide on 12 May 2018, 18:36, edited 1 time in total.
eway
Posts: 10
Joined: 30 Jun 2013, 12:44

Re: [Windows] Suppress CMD window

Post 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"
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Windows] Suppress CMD window

Post 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?
:idea: Please read the FAQ and How to Request Help.
eway
Posts: 10
Joined: 30 Jun 2013, 12:44

Re: [Windows] Suppress CMD window

Post 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?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Windows] Suppress CMD window

Post 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.
:idea: Please read the FAQ and How to Request Help.
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: [Windows] Suppress CMD window

Post 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.
Last edited by ZeroByDivide on 12 May 2018, 18:37, edited 1 time in total.
illusionist
Posts: 3
Joined: 04 May 2018, 15:11

Re: [Windows] Suppress CMD window

Post 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.
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: [Windows] Suppress CMD window

Post 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.
cmre222333
Posts: 1
Joined: 29 May 2018, 21:10

Re: [Windows] Suppress CMD window

Post 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 .
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Windows] Suppress CMD window

Post 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.
:idea: Please read the FAQ and How to Request Help.
rspierenburg
Posts: 5
Joined: 30 Mar 2017, 01:58

Re: [Windows] Suppress CMD window

Post 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.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Windows] Suppress CMD window

Post 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.
:idea: Please read the FAQ and How to Request Help.
RedSteelMoss
Posts: 1
Joined: 28 Dec 2018, 05:48

Re: [Windows] Suppress CMD window

Post 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.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Windows] Suppress CMD window

Post 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
:idea: Please read the FAQ and How to Request Help.
Post Reply