Command prompt no longer executing in Run External Program #4432

Closed
opened 2026-02-21 17:18:56 -05:00 by deekerman · 29 comments
Owner

Originally created by @Viridel on GitHub (Jun 25, 2016).

Whether it (cmd.exe) is part of the script line, or if removing that part and just having the BAT as the script line, it's no longer executing. It is possible to have it run via a BAT->EXE converter tool (then setting script.exe as the command line), but since CMD doesn't actually launch, it's impossible to do any code troubleshoting. In addition with this method (at least on my system) one copy of script.exe gets held in the Task Manager each time it executes.

Originally created by @Viridel on GitHub (Jun 25, 2016). Whether it (cmd.exe) is part of the script line, or if removing that part and just having the BAT as the script line, it's no longer executing. It is possible to have it run via a BAT->EXE converter tool (then setting script.exe as the command line), but since CMD doesn't actually launch, it's impossible to do any code troubleshoting. In addition with this method (at least on my system) one copy of script.exe gets held in the Task Manager each time it executes.
Author
Owner

@Chocobo1 commented on GitHub (Jun 26, 2016):

You might be affected by #5399.
and what is your qbittorrent version?

@Chocobo1 commented on GitHub (Jun 26, 2016): You might be affected by #5399. and what is your qbittorrent version?
Author
Owner

@Viridel commented on GitHub (Jun 26, 2016):

I:\qBittorrent\script.bat "%F"

Definitely doesn't exceed 260 characters :)

@Viridel commented on GitHub (Jun 26, 2016): I:\qBittorrent\script.bat "%F" Definitely doesn't exceed 260 characters :)
Author
Owner

@gddeluca commented on GitHub (Jun 26, 2016):

Having same problem. I believe (not positive) that while this was working in a previous release, the latest qbittorrent release has killed it. e.g. my command is

"e:\OneDrive\Misc Data\UnZipit.bat" "E:\P2P%N"

I altered the BAT file to put a PAUSE at the end so I could perhaps see what's going on, but it appears the BAT file is never started.

[Update] Tried adding CMD.EXE /C in front of the command - no effect. The qBittorrent log indicates it is trying to run the command, but there is no external evidence of it happening.

@gddeluca commented on GitHub (Jun 26, 2016): Having same problem. I believe (not positive) that while this was working in a previous release, the latest qbittorrent release has killed it. e.g. my command is "e:\OneDrive\Misc Data\UnZipit.bat" "E:\P2P\%N" I altered the BAT file to put a PAUSE at the end so I could perhaps see what's going on, but it appears the BAT file is never started. [Update] Tried adding CMD.EXE /C in front of the command - no effect. The qBittorrent log indicates it is trying to run the command, but there is no external evidence of it happening.
Author
Owner

@Chocobo1 commented on GitHub (Jun 26, 2016):

I confirm this is a bug.

@gddeluca
workaround for now, try: hh & "e:\OneDrive\Misc Data\UnZipit.bat" "E:\P2P\%N"

@Viridel
Try: hh & I:\qBittorrent\script.bat "%F"

@Chocobo1 commented on GitHub (Jun 26, 2016): I confirm this is a bug. @gddeluca workaround for now, try: `hh & "e:\OneDrive\Misc Data\UnZipit.bat" "E:\P2P\%N"` @Viridel Try: `hh & I:\qBittorrent\script.bat "%F"`
Author
Owner

@Viridel commented on GitHub (Jun 26, 2016):

I've reverted to 3.3.4, and will wait until 3.3.6 to re-evaluate.

@Viridel commented on GitHub (Jun 26, 2016): I've reverted to 3.3.4, and will wait until 3.3.6 to re-evaluate.
Author
Owner

@gddeluca commented on GitHub (Jun 26, 2016):

Do you mean me to substitute something for hh? or to just code it as shown. I tried it as shown and saw nothing different. What is hh meant to be?

[Update] Meanwhile, like Viridel, I've backed down to 3.3.4 to keep things working.

@gddeluca commented on GitHub (Jun 26, 2016): Do you mean me to substitute something for hh? or to just code it as shown. I tried it as shown and saw nothing different. What is hh meant to be? [Update] Meanwhile, like Viridel, I've backed down to 3.3.4 to keep things working.
Author
Owner

@Chocobo1 commented on GitHub (Jun 26, 2016):

@gddeluca

Do you mean me to substitute something for hh? or to just code it as shown.

Just as shown.

What is hh meant to be?

it's invoking Windows HTML Help, I'm trying to use it as a dummy command, but seems it doesn't workaround the problem. (works for me though...)

@Chocobo1 commented on GitHub (Jun 26, 2016): @gddeluca > Do you mean me to substitute something for hh? or to just code it as shown. Just as shown. > What is hh meant to be? it's invoking `Windows HTML Help`, I'm trying to use it as a dummy command, but seems it doesn't workaround the problem. (works for me though...)
Author
Owner

@gddeluca commented on GitHub (Jun 26, 2016):

OK, thanks for explaining hh. I've no problems remaining on 3.3.4 until this is corrected.

@gddeluca commented on GitHub (Jun 26, 2016): OK, thanks for explaining hh. I've no problems remaining on 3.3.4 until this is corrected.
Author
Owner

@Chocobo1 commented on GitHub (Jun 26, 2016):

@sledgehammer999
below is my findings:
won't work:

"c:\test\fff 1\zxcv 2.bat" "%R"

will work:

"c:\test\fff 1\zxcv 2.bat"
c:\"test\fff 1\zxcv 2.bat" "%R"

Since I can't find a way to solve this, I'm thinking of deleting the windows-specific code section, revert back to QProcess::startDetached(program);

@Chocobo1 commented on GitHub (Jun 26, 2016): @sledgehammer999 below is my findings: won't work: ``` batch "c:\test\fff 1\zxcv 2.bat" "%R" ``` will work: ``` batch "c:\test\fff 1\zxcv 2.bat" c:\"test\fff 1\zxcv 2.bat" "%R" ``` Since I can't find a way to solve this, I'm thinking of deleting the windows-specific code section, revert back to `QProcess::startDetached(program);`
Author
Owner

@gddeluca commented on GitHub (Jun 26, 2016):

Hmmm, I guiess what worked in 3.3.4 had some other problem, otherwise, why modify code that is working? As a developer myself, I well know the 'don't fix what ain't broken' mantra.

@gddeluca commented on GitHub (Jun 26, 2016): Hmmm, I guiess what worked in 3.3.4 had some other problem, otherwise, why modify code that is working? As a developer myself, I well know the 'don't fix what ain't broken' mantra.
Author
Owner

@sledgehammer999 commented on GitHub (Jul 12, 2016):

@Chocobo1 I today tried to fix this. But I can see why you gave up. I think we need to revert back to the pre-v3.3.5 way of calling programs. The problem described here is actually a Windows/cmd.exe bug involving batch files.
See these 2 relevant SO posts:

  1. https://stackoverflow.com/questions/18877212/trouble-running-a-batch-file-with-a-space-in-the-path-and-space-in-the-argument
  2. https://stackoverflow.com/questions/17674255/why-does-windows-start-command-not-work-with-spaces-in-arguments-and-path

I get the same error as the one they report for the "start" command. I believe "cmd.exe /c" uses the same command internally.

@sledgehammer999 commented on GitHub (Jul 12, 2016): @Chocobo1 I today tried to fix this. But I can see why you gave up. I think we need to revert back to the pre-v3.3.5 way of calling programs. The problem described here is actually a Windows/cmd.exe bug involving batch files. See these 2 relevant SO posts: 1. https://stackoverflow.com/questions/18877212/trouble-running-a-batch-file-with-a-space-in-the-path-and-space-in-the-argument 2. https://stackoverflow.com/questions/17674255/why-does-windows-start-command-not-work-with-spaces-in-arguments-and-path I get the same error as the one they report for the "start" command. I believe "cmd.exe /c" uses the same command internally.
Author
Owner

@tekko commented on GitHub (Jul 13, 2016):

http://ss64.com/nt/cmd.html

Looking at the examples at the bottom, you need to quote the whole line that u want to start with cmd /c
Maybe try to prepend (cmd /c ") and insert " at the end ?

@tekko commented on GitHub (Jul 13, 2016): http://ss64.com/nt/cmd.html Looking at the examples at the bottom, you need to quote the whole line that u want to start with cmd /c Maybe try to prepend (cmd /c ") and insert " at the end ?
Author
Owner

@Chocobo1 commented on GitHub (Jul 15, 2016):

Looking at the examples at the bottom, you need to quote the whole line that u want to start with cmd /c
Maybe try to prepend (cmd /c ") and insert " at the end ?

I guess the info in the link is right. Thanks!


@sledgehammer999
I've updated #5408. It contains a fix for https://github.com/qbittorrent/qBittorrent/issues/5439#issuecomment-228616817 and now all my test cases work correctly.
Well... your choice to close (and revert the code) or accept that PR.

@Chocobo1 commented on GitHub (Jul 15, 2016): > Looking at the examples at the bottom, you need to quote the whole line that u want to start with cmd /c > Maybe try to prepend (cmd /c ") and insert " at the end ? I guess the info in the link is right. Thanks! --- @sledgehammer999 I've updated #5408. It contains a fix for https://github.com/qbittorrent/qBittorrent/issues/5439#issuecomment-228616817 and now all my test cases work correctly. Well... your choice to close (and revert the code) or accept that PR.
Author
Owner

@sledgehammer999 commented on GitHub (Jul 17, 2016):

Fix accepted. Going to release v3.3.6 later today.

@sledgehammer999 commented on GitHub (Jul 17, 2016): Fix accepted. Going to release v3.3.6 later today.
Author
Owner

@Chocobo1 commented on GitHub (Jul 17, 2016):

Fix accepted. Going to release v3.3.6 later today.

Nice 👍 and don't forget #5409 & #5474.

@Chocobo1 commented on GitHub (Jul 17, 2016): > Fix accepted. Going to release v3.3.6 later today. Nice :+1: and don't forget #5409 & #5474.
Author
Owner

@DrKittens commented on GitHub (Jul 21, 2016):

We forgot to document the syntax, can an example please be added instead of the "Tip" at the bottom of the "options > Downloads" tab or at the very least say to encapsulate everything seperately because they're ALL arguments now (qbt runs cmd /c |what we enter in the field goes here|)

It makes sense once you see an example that works but it took me a while to actually find a working example haha

Relevant Support thread post: https://qbforums.shiki.hu/index.php?topic=4223.msg23001#msg23001

@DrKittens commented on GitHub (Jul 21, 2016): We forgot to document the syntax, can an example please be added instead of the "Tip" at the bottom of the "options > Downloads" tab or at the very least say to **encapsulate everything seperately** because they're ALL arguments now (qbt runs cmd /c |what we enter in the field goes here|) It makes sense once you see an example that works but it took me a while to actually find a working example haha Relevant Support thread post: https://qbforums.shiki.hu/index.php?topic=4223.msg23001#msg23001
Author
Owner

@ArionMiles commented on GitHub (Sep 6, 2016):

Even on the v3.3.6, the issue persists.

@ArionMiles commented on GitHub (Sep 6, 2016): Even on the v3.3.6, the issue persists.
Author
Owner

@war59312 commented on GitHub (Jan 21, 2017):

Here is my Kodi Notification script which works around this bug.

Options > Downloads > "Run external programon torrent completion" is set to:

"D:\Appz\qBittorrentPortable\TorrentCompleted.cmd" "%N"

@echo off

REM Created By war59312
REM Created On 21st Jan. 2017

REM Clear Screen
cls

REM Set Script Parameters Below:

REM Set Path To Curl - Needed To Be Able To Send A MSG To Kodi
pushd "D:\libraries\curl-7.20.0-ssl-sspi-zlib-static-bin-w32\"

REM Kodi IP Address
set KodiIPAddress=192.168.10.156

REM MSG Title
set MSGTitle=Torrent Completed

REM Message Text
set MSG=%1

REM Show Torrent Completed MSG On Kodi
start cmd /k "curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"GUI.ShowNotification\", \"params\": {\"title\": \"%MSGTitle%\", \"message\": \"%MSG%\"}, \"id\": 1}" http://%KodiIPAddress%:8080/jsonrpc >NUL  2>NUL && exit"

:Done
REM Exit Script
exit
@war59312 commented on GitHub (Jan 21, 2017): Here is my Kodi Notification script which works around this bug. Options > Downloads > "Run external programon torrent completion" is set to: > "D:\Appz\qBittorrentPortable\TorrentCompleted.cmd" "%N" ``` @echo off REM Created By war59312 REM Created On 21st Jan. 2017 REM Clear Screen cls REM Set Script Parameters Below: REM Set Path To Curl - Needed To Be Able To Send A MSG To Kodi pushd "D:\libraries\curl-7.20.0-ssl-sspi-zlib-static-bin-w32\" REM Kodi IP Address set KodiIPAddress=192.168.10.156 REM MSG Title set MSGTitle=Torrent Completed REM Message Text set MSG=%1 REM Show Torrent Completed MSG On Kodi start cmd /k "curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"GUI.ShowNotification\", \"params\": {\"title\": \"%MSGTitle%\", \"message\": \"%MSG%\"}, \"id\": 1}" http://%KodiIPAddress%:8080/jsonrpc >NUL 2>NUL && exit" :Done REM Exit Script exit ```
Author
Owner

@spidawg commented on GitHub (Mar 6, 2017):

This is still an issue in 3.3.11

@spidawg commented on GitHub (Mar 6, 2017): This is still an issue in 3.3.11
Author
Owner

@infideler commented on GitHub (May 27, 2017):

Also having this issue on 3.3.12, unfortunately.

@infideler commented on GitHub (May 27, 2017): Also having this issue on 3.3.12, unfortunately.
Author
Owner

@Chocobo1 commented on GitHub (May 27, 2017):

@infideler

Can you try out the build in https://github.com/qbittorrent/qBittorrent/issues/5497#issuecomment-284640536 and let me know if it works?

@Chocobo1 commented on GitHub (May 27, 2017): @infideler Can you try out the build in https://github.com/qbittorrent/qBittorrent/issues/5497#issuecomment-284640536 and let me know if it works?
Author
Owner

@war59312 commented on GitHub (May 28, 2017):

@Chocobo1 Pretty sure all you really needed to do was change in Line 264 cmd.exe /C to cmd.exe /K.

@war59312 commented on GitHub (May 28, 2017): @Chocobo1 Pretty sure all you really needed to do was change in Line 264 `cmd.exe /C` to `cmd.exe /K`.
Author
Owner

@Chocobo1 commented on GitHub (May 29, 2017):

@Chocobo1 Pretty sure all you really needed to do was change in Line 264 cmd.exe /C to cmd.exe /K.

I don't think so, the external program is supposed to run and exit, using /K will cause it keep running, right?

@Chocobo1 commented on GitHub (May 29, 2017): >@Chocobo1 Pretty sure all you really needed to do was change in Line 264 cmd.exe /C to cmd.exe /K. I don't think so, the external program is supposed to run and exit, using `/K` will cause it keep running, right?
Author
Owner

@war59312 commented on GitHub (May 31, 2017):

Whoops, you are correct... Guess I was thinking something else for some odd reason.

Sorry about that.

/C      Carries out the command specified by string and then terminates

/K      Carries out the command specified by string but remains
@war59312 commented on GitHub (May 31, 2017): Whoops, you are correct... Guess I was thinking something else for some odd reason. Sorry about that. ``` /C Carries out the command specified by string and then terminates /K Carries out the command specified by string but remains ```
Author
Owner

@infideler commented on GitHub (Jun 4, 2017):

@Chocobo1

Sorry for the delay. Can confirm that build 3.4.0alpha does work as expected.

Run external program on torrent completion:
"C:\Path\To\Batch\mybatchfile.bat" "%N"
@infideler commented on GitHub (Jun 4, 2017): @Chocobo1 Sorry for the delay. Can confirm that build 3.4.0alpha does work as expected. ``` Run external program on torrent completion: "C:\Path\To\Batch\mybatchfile.bat" "%N" ```
Author
Owner

@j-marcon commented on GitHub (Nov 14, 2017):

Hi,
Long story short, I've jumped from a version <3.3.4 to 3.3.16, realised that the the external program feature didn't work anymore and decided to go to 3.4.0beta since the code was reverted according to this thread. However, it seems like running an external program on 3.4.0beta is still broken. Anyone else has observed this? I run something similar to what @infideler used:

"C:\Path\To\Batch\mybatchfile.bat" "%N"

I've tried with and without quotation marks, with left and right slashes and nothing seems to work. The cmd prompt never opens. Any idea?

@j-marcon commented on GitHub (Nov 14, 2017): Hi, Long story short, I've jumped from a version <3.3.4 to 3.3.16, realised that the the external program feature didn't work anymore and decided to go to 3.4.0beta since the code was reverted according to this thread. However, it seems like running an external program on 3.4.0beta is still broken. Anyone else has observed this? I run something similar to what @infideler used: > "C:\Path\To\Batch\mybatchfile.bat" "%N" I've tried with and without quotation marks, with left and right slashes and nothing seems to work. The cmd prompt never opens. Any idea?
Author
Owner

@Chocobo1 commented on GitHub (Nov 14, 2017):

Any idea?

Yes, try this 3.4.0beta2 x64 build and see if it works: https://github.com/Chocobo1/temp/raw/master/3/qbittorrent.exe
The relevant code wasn't reverted yet.

@Chocobo1 commented on GitHub (Nov 14, 2017): >Any idea? Yes, try this 3.4.0beta2 x64 build and see if it works: https://github.com/Chocobo1/temp/raw/master/3/qbittorrent.exe The relevant code wasn't reverted yet.
Author
Owner

@j-marcon commented on GitHub (Nov 14, 2017):

Thanks, @Chocobo1. It works perfectly fine now. Will this be the case in the release version of 3.4.0 too?

@j-marcon commented on GitHub (Nov 14, 2017): Thanks, @Chocobo1. It works perfectly fine now. Will this be the case in the release version of 3.4.0 too?
Author
Owner

@j-marcon commented on GitHub (Nov 20, 2017):

Hi again, I've been prompted by the GUI to update to 4.0.0. Has anyone tested that the feature works in 4.0.0 release?

@j-marcon commented on GitHub (Nov 20, 2017): Hi again, I've been prompted by the GUI to update to 4.0.0. Has anyone tested that the feature works in 4.0.0 release?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/qBittorrent#4432
No description provided.