[SOLVED] Running External Program - BAT File - Copy Script

Windows specific questions, problems.
Post Reply
natelabo

[SOLVED] Running External Program - BAT File - Copy Script

Post by natelabo »

Can someone please tell me the syntax to run a BAT file?

I cannot get qBittorrent to execute it...

I have tried:

Code: Select all

cmd.exe /C C:\Users\torrentuser\torrenthandler.bat "%D" "%N" "%L" "%C" "%F"

Code: Select all

C:\Users\torrentuser\torrenthandler.bat "%D" "%N" "%L" "%C" "%F"

Code: Select all

"C:\Users\torrentuser\torrenthandler.bat" "%D" "%N" "%L" "%C" "%F"
None of these have worked.

Recent convert from uTorrent. Love this program. Just can't get my script to run...

Setup:
Server 2012 R2
qBittorrent v3.3.10

**************** My last post includes the script and syntax to run *************
Last edited by natelabo on Tue Dec 27, 2016 4:31 am, edited 1 time in total.
KitKat

Re: Running External Program - BAT File

Post by KitKat »

[quote="natelabo"]

Code: Select all

"C:\Users\torrentuser\torrenthandler.bat" "%D" "%N" "%L" "%C" "%F"
[/quote]
This is the Correct Syntax Structure.

Quickly confirmed it wasn't an application fault with this test script.

Code: Select all

echo Arg 1: %1 >> qbittorrentoutput.txt
echo Arg 2: %2 >> qbittorrentoutput.txt
echo Arg 3: %3 >> qbittorrentoutput.txt
echo Arg 4: %4 >> qbittorrentoutput.txt
echo Arg 5: %5 >> qbittorrentoutput.txt
And this launch parameter:

Code: Select all

"C:\Folder1\Folder Space\torrenthandler.bat" "%D" "%N" "%L" "%C" "%F"
Please make sure your batch file actually works/the data you're passing to it with qbittorrent is what the script expects to see.
You can quickly check whether scripts execute properly by deleting a small file from a completed torrent and forcing a recheck.
The script i posted above will drop a .txt file into the same folder as the .bat file when executed that contains the values qbittorrent returns for those variables, it may be returning something unexpected!?

If your script moves files around or renames things you could have a permissions error, try running qbittorrent as administrator if you are not already?
Last edited by KitKat on Thu Dec 22, 2016 1:38 pm, edited 1 time in total.
natelabo

Re: Running External Program - BAT File

Post by natelabo »

KitKat Thanks for the reply.

I've tried running as administrator and a standard user.

I copied your test script...

It says that it runs in the logs... Yet nothing runs?

Anything else I could try?
KitKat

Re: Running External Program - BAT File

Post by KitKat »

Only thing i can think of (since everything you're doing is correct!) would be a group policy/standard preventing applications from directly calling cmd.exe
qbittorrent attempts to run "cmd.exe /c <your commandline here>"

eg "cmd.exe /c "C:\script.bat" "%F""

Try pressing the windows key + R to open the run menu then enter cmd.exe, if command prompt does not popup then it could be a Path variable issue.

Worstcase you can downgrade to version 3.3.3 and use the commandline: cmd.exe /c "<your commandline here>"
As the method + syntax for running external programs changed in version 3.3.4

Old syntax was: [quote="natelabo"]

Code: Select all

cmd.exe /C C:\Users\torrentuser\torrenthandler.bat "%D" "%N" "%L" "%C" "%F"
[/quote]

If its not a permissions/policy/path error on your machine, i'd suggest opening an issue ticket on the tracker:
https://github.com/qbittorrent/qBittorrent/

And linking to this thread and summarising the problem.
Last edited by KitKat on Fri Dec 23, 2016 9:51 am, edited 1 time in total.
natelabo

Re: Running External Program - BAT File

Post by natelabo »

KitKat thanks for your input...

Further testing looks like this syntax is working for me:

Code: Select all

C:\Users\torrentuser\torrenthandler.bat "%N" "%L" "%F" "%C"
I had to modify my batch script...

If anyone is interested I am using it to copy data to a storage location. Code looks like this:

Code: Select all

@echo off
echo ********************************************* >> C:\Users\torrentuser\Desktop\CopyProgress.txt
echo Run on %date% at %time% >> C:\Users\torrentuser\Desktop\CopyProgress.txt

set name=%1
set category=%2
set contentpath=%3
set filecount=%4
set savepartition=\\STORAGE\Media\New

rem If category is "Music"
if %category%=="Music" goto music

rem If category is "Shows"
if %category%=="Shows" goto shows

rem If category is "Movies"
if %category%=="Movies" goto movies

rem If category is "Books"
if %category%=="Books" goto books

rem If category is "Blank"
echo **Undefined >> C:\Users\torrentuser\Desktop\CopyProgress.txt
rem Double underscores so the folders are easier to spot (listed on top in explorer)
set todir=%savepartition%\__%name%
goto filecount

:music
echo **Music >> C:\Users\torrentuser\Desktop\CopyProgress.txt
set todir=%savepartition%\Music\%name%
goto filecount

:shows
echo **Shows >> C:\Users\torrentuser\Desktop\CopyProgress.txt
set todir=%savepartition%\Shows\%name%
goto filecount

:movies
echo **Movies >> C:\Users\torrentuser\Desktop\CopyProgress.txt
set todir=%savepartition%\Movies\%name%
goto filecount

:books
echo **Books >> C:\Users\torrentuser\Desktop\CopyProgress.txt
set todir=%savepartition%\Books\%name%
goto filecount

:filecount
echo todir = %todir >> C:\Users\torrentuser\Desktop\CopyProgress.txt
rem Determine Torrent filecount
if %filecount%=="1" goto copyfile
if not %filecount%=="1" goto copyall

:copyall
echo Copy all contents of %contentpath% to %todir% >> C:\Users\torrentuser\Desktop\CopyProgress.txt
xcopy %contentpath%\*.* %todir% /S /I /Y
goto write

:copyfile
rem Copies single file from fromdir to todir
echo Copy %contentpath% to %todir% >> C:\Users\torrentuser\Desktop\CopyProgress.txt
xcopy %contentpath% %todir%\ /Y
goto write

:write
if errorlevel 4 goto lowmemory  
if errorlevel 0 goto noerrors

:lowmemory 
echo %date% at %time%: Handled torrent %name% %category% - FAILED >> C:\Users\torrentuser\Desktop\HandledTorrents.txt
goto exit 

:noerrors
echo %date% at %time%: Handled torrent %name% %category% >> C:\Users\torrentuser\Desktop\HandledTorrents.txt
goto exit

:exit
end
I am not the original creator of the script... But I'm not sure of where I got it from. Hope the original creator doesn't mind me posting it...
Post Reply