How to make "script-torrent-done-filename" working in windows

Ask for help and report issues with the Windows version of Transmission
i3laze
Posts: 4
Joined: Sun Feb 25, 2018 12:19 pm

Re: How to make "script-torrent-done-filename" working in windows

Post by i3laze »

+1 for not working.
I've updated "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Transmission\ImagePath" with log a --logfile.

I see a successful invocation in a log file
Calling script "C:\Windows\ServiceProfiles\LocalService\AppData\Local\transmission-daemon\oncomplete.cmd"
but nothing actually happens at all.

Actually, basic .exe files are fired fine, but .cmds are not.
"c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" doesn't fire too(
Last edited by i3laze on Sun Feb 25, 2018 12:59 pm, edited 2 times in total.
mike.dld
Transmission Developer
Posts: 306
Joined: Wed Dec 25, 2013 10:56 pm

Re: How to make "script-torrent-done-filename" working in windows

Post by mike.dld »

@i3laze I've made some changes to the script execution code recently, see https://github.com/transmission/transmission/issues/405. If you could try latest nightly and report back what would be great. If you already are using latest nightly, I believe there should either be an error message in the log file or an error in your script.
i3laze
Posts: 4
Joined: Sun Feb 25, 2018 12:19 pm

Re: How to make "script-torrent-done-filename" working in windows

Post by i3laze »

Thank you!
Congratulations on being the first officially working Torrent NT-service under Windows :!:

1. Particular transmission-2.93+-r96926a8337-x64 build has start time over 180 sec+ (during this time GUI is inaccessible):

Code: Select all

[2018-02-25 16:40:45.169] Loaded 2 torrents (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\session.c:2174)
[2018-02-25 16:40:45.169] Port Forwarding (NAT-PMP) initnatpmp succeeded (0) (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\natpmp.c:73)
[2018-02-25 16:40:45.169] Port Forwarding (NAT-PMP) sendpublicaddressrequest succeeded (2) (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\natpmp.c:73)
[2018-02-25 16:43:46.195] Port Forwarding Port Forwarding (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\port-forwarding.c:107)

Code: Select all

[2018-02-25 17:04:40.129] Port Forwarding (NAT-PMP) sendpublicaddressrequest succeeded (2) (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\natpmp.c:73)
[2018-02-25 17:07:40.124] Port Forwarding Port Forwarding (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\port-forwarding.c:107)
[2018-02-25 17:07:40.124] web will verify tracker certs using envvar CURL_CA_BUNDLE: none (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\web.c:383)
[2018-02-25 17:07:40.124] web NB: this only works if you built against libcurl with openssl or gnutls, NOT nss (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\web.c:384)
[2018-02-25 17:07:40.124] web NB: invalid certs will show up as 'Could not connect to tracker' like many other errors (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\web.c:385)
[2018-02-25 17:07:40.124] Searching for web interface file "C:\Windows\ServiceProfiles\LocalService\AppData\Local/Transmission/Web/index.html" (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\platform.c:470)
[2018-02-25 17:07:40.124] Searching for web interface file "C:\Windows\ServiceProfiles\LocalService\AppData\Roaming/Transmission/Web/index.html" (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\platform.c:470)
[2018-02-25 17:07:40.124] Searching for web interface file "C:\ProgramData/Transmission/Web/index.html" (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\platform.c:470)
[2018-02-25 17:07:40.124] Searching for web interface file "C:\Program Files\Transmission/Web/index.html" (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\platform.c:470)
[2018-02-25 17:07:41.131] [censored] Scrape error: Tracker gave HTTP response code 404 (Not Found) (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\announcer.c:1318)
[2018-02-25 17:07:41.131] [censored] Retrying scrape in 20 seconds. (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\announcer.c:1327)
[2018-02-25 17:07:41.131] [censored] Scrape error: Tracker gave HTTP response code 404 (Not Found) (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\announcer.c:1318)
[2018-02-25 17:07:41.131] [censored] Retrying scrape in 20 seconds. (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\announcer.c:1327)
[2018-02-25 17:07:41.131] [censored] Scrape error: Tracker gave HTTP response code 404 (Not Found) (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\announcer.c:1318)
[2018-02-25 17:07:41.131] [censored] Retrying scrape in 20 seconds. (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\announcer.c:1327)
[2018-02-25 17:07:43.153] Port Forwarding Port Forwarding (C:\Transmission\Jenkins\workspace\trunk-win32\arch\x64\label\pepito-win10\libtransmission\port-forwarding.c:107)
2. Working Path for everything inside a script is C:\, and without full path specified script may be fired only when placed in C:\ directly.
I expect Working Path to be Transmission Config Folder, not C:\.

3. Log file says Calling script "oncomplete.cmd" successfully every time no matter file exists or not.

4. Although generic .exe does launch, I'm unable to fire a PowerShell script (I've converted one from Python) at all :evil: . I've tried all means:
powershell.exe does launch when placed inside .cmd, but powershell.exe /file "fullpath" or -file "fullpath" does not.
mike.dld
Transmission Developer
Posts: 306
Joined: Wed Dec 25, 2013 10:56 pm

Re: How to make "script-torrent-done-filename" working in windows

Post by mike.dld »

i3laze wrote:1. Particular transmission-2.93+-r96926a8337-x64 build has start time over 180 sec+ (during this time GUI is inaccessible): ...
This seems to be an issue affecting all released and unreleased Windows builds. Disabling port forwarding helps and it's on our TODO list to fix it properly.
i3laze wrote:2. Working Path for everything inside a script is C:\, and without full path specified script may be fired only when placed in C:\ directly.
I expect Working Path to be Transmission Config Folder, not C:\.
Why do you expect that? The working directory is not documented anywhere and so you shouldn't expect anything. On *NIX systems, it's currently set to /, so it's natural to set it to the root of the disk on Windows as well. The Transmission configuration directory is there for Transmission itself, what would be the point of setting it as working directory for users' scripts? Generally speaking, without full path specified we don't know which script exactly you want to execute, so putting it into C:\ is not a good idea either (if it works now it doesn't mean it'll work tomorrow since, again, the behavior is not documented).
i3laze wrote:3. Log file says Calling script "oncomplete.cmd" successfully every time no matter file exists or not.
Is there anything after that line in the log file to suggest that the execution failed?
i3laze wrote:4. Although generic .exe does launch, I'm unable to fire a PowerShell script (I've converted one from Python) at all :evil: . I've tried all means:
powershell.exe does launch when placed inside .cmd, but powershell.exe /file "fullpath" or -file "fullpath" does not.
When you say "generic .exe does launch", does that mean it launches when specified directly as a completion script or from within the batch file specified as a completion script? What are you doing to verify that the script launches or not? Did you try a very basic script that e.g. prints a line to a file? Did you check %errorlevel% in the batch script after attempting to run powershell? Did you try redirecting powershell's standard output and error streams to a file to see if it prints an error or something? Also note that when running Transmission daemon as a service the execution environment is a bit different, e.g. there could be issues if the process you're launching is interactive (prompts for user input in the terminal, shows windows, etc.), or if it accesses drive letter-mapped network shares, or who knows what else.
i3laze
Posts: 4
Joined: Sun Feb 25, 2018 12:19 pm

Re: How to make "script-torrent-done-filename" working in windows

Post by i3laze »

2. On Windows working folder is either specified in the shortcut, or is the folder of .exe file, or c:\windows\system32 (if run under Local System). C:\ is a NIX way :)

3. Can't reproduce anymore. Log files now correctly states if file exists or not.

4. My fault, "Local Service" account is rarely used (I confused it with "Local system"). The account had no rights outside it's LocalService folder.
My test PS-script was trying to create a directory. I've granted full access on the target folder and my test completed fine.

Here's contents of working .cmd, which passes Transmission variables to a PS-script:

Code: Select all

powershell.exe -ExecutionPolicy Bypass -File "C:\Windows\ServiceProfiles\LocalService\AppData\Local\transmission-daemon\oncomplete.ps1" %TR_TORRENT_DIR% %TR_TORRENT_NAME% %TR_TORRENT_ID%
Header or .ps1 (with =hardcoded test strings):

Code: Select all

 param (
    [string]$TR_TORRENT_DIR = "D:\Serials",
    [string]$TR_TORRENT_NAME= "[censored]",
    [string]$TR_TORRENT_ID  = "32"
 )
FYI, the script parses title, then sorts series to folders and deletes the torrent by invoking transmission-remote.
One day I will drop this old Python setup for Sonarr.

P.S. Just rechecked: "script-torrent-done" .cmd definitely not invoked on 2.93 master build, only on 2.93+ nightly one.
mike.dld
Transmission Developer
Posts: 306
Joined: Wed Dec 25, 2013 10:56 pm

Re: How to make "script-torrent-done-filename" working in windows

Post by mike.dld »

If I were you I would access environment variables from the PowerShell script directly instead of passing them as arguments to prevent issues with e.g. torrent name containing spaces or other special characters. Just use $Env:TR_TORRENT_DIR and the like.
Post Reply