-exec command bugged after version 5.0.3

Support for Windows users
Post Reply
scherzeking
Posts: 10
Joined: 16 Dec 2021, 21:39

-exec command bugged after version 5.0.3

Post by scherzeking »

Hello,
I want to execute another batch file with -exec. However, In the latest version this doesn't work anymore. With version 5.0.3 it's working fine.
The script looks like this: ... -exec "Z:\Input Serien\RenameExtra.bat" ...
The error is: "The command "Z:\Input" is not recognized as an internal or external command, operable program or batch file.
[C:\WINDOWS\system32\cmd.exe, /c, Z:\Input Serien\RenameExtra.bat, ..."
It looks like this can't be executed, because of the space in the path. I don't see in the changelogs any changes regarding the -exec command. Any help?
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: -exec command bugged after version 5.0.3

Post by rednoah »

:?: What happens if you run the following command?

Code: Select all

"C:\WINDOWS\system32\cmd.exe" /c "Z:\Input Serien\RenameExtra.bat"


:idea: Newer versions of FileBot prepend cmd /c so that you can run commands from the path and *.bat files, since cmd is now interpreting things. I'm fairly sure that executing *.bat files didn't work at all in the past since they're not executable files, just text files read by cmd, but perhaps Windows fixed that internally at some point?




EDIT:

:!: Note that I cannot reproduce the problem, so there's more to it.

test.bat

Code: Select all

echo "test.bat was called"
echo %*
Command and Console Output

Code: Select all

filebot -find *.mp4 -exec "C:\New Folder\test.bat" 1 2 3

Code: Select all

C:\New folder\Alias.1x01.mp4

C:\New Folder>echo "test.bat was called"
"test.bat was called"

C:\New Folder>echo 1 2 3
1 2 3



EDIT 2:

:?: Please post the output:

Shell: Select all

filebot -script fn:sysinfo

Shell: Select all

filebot -script fn:sysenv
:?: The complete filebot command and console output that you are using to run tests would also be useful.
:idea: Please read the FAQ and How to Request Help.
scherzeking
Posts: 10
Joined: 16 Dec 2021, 21:39

Re: -exec command bugged after version 5.0.3

Post by scherzeking »

Sadly Your first command doesn't change anything. The error message is the same.

However, the quick test you suggested is working on my end:
Command and Console Output:

Code: Select all

Z:\Input Serien\Alias>filebot -find *.mkv -exec "Z:\Input Serien\test.bat" 1 2 3
Z:\Input Serien\Alias\Alias - S01E01.mkv

Z:\Input Serien\Alias>echo "test.bat was called"
"test.bat was called"

Z:\Input Serien\Alias>echo 1 2 3
1 2 3
Z:\Input Serien\Alias\Alias - S01E02.mkv

Z:\Input Serien\Alias>
I usually collect several folders and drag and drop the folder into a .bat file. After a few more tests, I've figured out that the problem is somewhere in the parameters I have. Without them the command works fine. How can I set the correct behavior so that the first parameter after -exec is the batch file to run via cmd and the rest are parameters for this test.bat file? Again, this worked with 5.0.3.

Simple test command and output (german os):

Code: Select all

Z:\Input Serien\Alias>filebot -find *.mkv -r -exec "Z:\Input Serien\test.bat" "{folder}\{historic.f.dir.name}"
Z:\Input Serien\Alias\Alias - S01E01.mkv
Der Befehl "Z:\Input" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
[C:\WINDOWS\system32\cmd.exe, /c, Z:\Input Serien\test.bat, Z:\Input Serien\Alias\] failed (1)
filebot -script fn:sysinfo

Code: Select all

FileBot 5.1.2 (r10125)
JNA Native: 6.1.6
MediaInfo: 23.10
7-Zip-JBinding: 16.02
Tools: fpcalc/1.5.0
Extended Attributes: OK
Unicode Filesystem: OK
Script Bundle: 2023-11-06 (r952)
Groovy: 4.0.15
JRE: OpenJDK Runtime Environment 17.0.8
JVM: OpenJDK 64-Bit Server VM
CPU/MEM: 16 Core / 8 GB Max Memory / 140 MB Used Memory
OS: Windows 10 (amd64)
STORAGE: NTFS [(C:)] @ 113 GB | NTFS [Lokaler Datentrõger] @ 1.5 TB | NTFS [Fast] @ 1.9 TB | NTFS [Seagate Expansion Drive] @ 2.2 TB | NTFS [Hitachi] @ 673 GB | NTFS [Archiv] @ 22 TB
DATA: C:\Users\scherzeking\AppData\Roaming\FileBot
Package: MSI
License: FileBot License PX31332569 (Valid-Until: 2071-12-04)
Done ?(?????)?
filebot -script fn:sysenv

Code: Select all

# Local Time #
Sun Dec 31 14:03:41 CET 2023

# Process Tree #
C:\Windows\explorer.exe
└─ C:\Windows\System32\cmd.exe
   └─ D:\Program Files\FileBot\filebot.exe
      └─ D:\Program Files\FileBot\jre\bin\java.exe

# Environment Variables #
=::: ::\
=C:: C:\Windows\System32
=ExitCode: 00000000
ACSetupSvcPort: 23210
ACSvcPort: 17532
ALLUSERSPROFILE: C:\ProgramData
AMDRMPATH: C:\Program Files\AMD\RyzenMaster\
APPDATA: C:\Users\scherzeking\AppData\Roaming
COMPUTERNAME: ASUS-PC
ChocolateyInstall: C:\ProgramData\chocolatey
ChocolateyLastPathUpdate: 133168683023187149
ChocolateyToolsLocation: C:\tools
ComSpec: C:\WINDOWS\system32\cmd.exe
CommonProgramFiles: C:\Program Files\Common Files
CommonProgramFiles(x86): C:\Program Files (x86)\Common Files
CommonProgramW6432: C:\Program Files\Common Files
DriverData: C:\Windows\System32\Drivers\DriverData
HOMEDRIVE: C:
HOMEPATH: \Users\scherzeking
JAVA_HOME: C:\PROGRA~1\Java\JDK-13~1.2
JD2_HOME: C:\Program Files (x86)\JDownloader 2.0
LOCALAPPDATA: C:\Users\scherzeking\AppData\Local
LOGONSERVER: \\ASUS-PC
NUMBER_OF_PROCESSORS: 16
OS: Windows_NT
OneDrive: C:\Users\scherzeking\OneDrive
PATHEXT: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE: AMD64
PROCESSOR_IDENTIFIER: AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD
PROCESSOR_LEVEL: 23
PROCESSOR_REVISION: 7100
PROMPT: $P$G
PSModulePath: C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PUBLIC: C:\Users\Public
Path: c:\program files (x86)\common files\oracle\java\javapath;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\windows\system32\openssh\;c:\program files\dotnet\;d:\program files (x86)\streamlink\bin;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\windows\system32\openssh\;c:\programdata\chocolatey\bin;c:\program files\putty\;c:\tools\nirlauncher\nirsoft;c:\program files\microsoft sql server\120\tools\binn\;d:\program files\git\cmd;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;D:\Program Files\FileBot\;C:\Users\scherzeking\AppData\Local\Programs\Python\Python310\Scripts\;C:\Users\scherzeking\AppData\Local\Programs\Python\Python310\;C:\Users\scherzeking\AppData\Local\Microsoft\WindowsApps;;D:\Program Files\JetBrains\PhpStorm 2019.3.1\bin;;D:\Program Files\FileBot\jre\bin
PhpStorm: D:\Program Files\JetBrains\PhpStorm 2019.3.1\bin;
ProgramData: C:\ProgramData
ProgramFiles: C:\Program Files
ProgramFiles(x86): C:\Program Files (x86)
ProgramW6432: C:\Program Files
RlsSvcPort: 22112
SESSIONNAME: Console
SystemDrive: C:
SystemRoot: C:\WINDOWS
TEMP: C:\Users\SCHERZ~1\AppData\Local\Temp
TMP: C:\Users\SCHERZ~1\AppData\Local\Temp
USERDOMAIN: ASUS-PC
USERDOMAIN_ROAMINGPROFILE: ASUS-PC
USERNAME: scherzeking
USERPROFILE: C:\Users\scherzeking
windir: C:\WINDOWS

# Java System Properties #
application.deployment: msi
application.dir: C:\Users\scherzeking\AppData\Roaming\FileBot
file.encoding: Cp1252
file.separator: \
grape.root: C:\Users\scherzeking\AppData\Roaming\FileBot\grape
http.agent: FileBot/5.1.2
java.class.path: D:\Program Files\FileBot\jar\filebot.jar
java.class.version: 61.0
java.home: D:\Program Files\FileBot\jre
java.io.tmpdir: C:\Users\scherzeking\AppData\Roaming\FileBot\tmp
java.library.path: D:\Program Files\FileBot\lib
java.net.useSystemProxies: true
java.runtime.name: OpenJDK Runtime Environment
java.runtime.version: 17.0.8+7
java.specification.name: Java Platform API Specification
java.specification.vendor: Oracle Corporation
java.specification.version: 17
java.vendor: Eclipse Adoptium
java.vendor.url: https://adoptium.net/
java.vendor.url.bug: https://github.com/adoptium/adoptium-support/issues
java.vendor.version: Temurin-17.0.8+7
java.version: 17.0.8
java.version.date: 2023-07-18
java.vm.compressedOopsMode: Zero based
java.vm.info: mixed mode, sharing
java.vm.name: OpenJDK 64-Bit Server VM
java.vm.specification.name: Java Virtual Machine Specification
java.vm.specification.vendor: Oracle Corporation
java.vm.specification.version: 17
java.vm.vendor: Eclipse Adoptium
java.vm.version: 17.0.8+7
jdk.debug: release
jdk.logger.packages: net.filebot.Logging
jna.boot.library.path: D:\Program Files\FileBot\lib
jna.library.path: D:\Program Files\FileBot\lib
jna.loaded: true
jna.noclasspath: true
jna.nosys: true
jna.nounpack: true
jnidispatch.path: D:\Program Files\FileBot\lib\jnidispatch.dll
line.separator:

native.encoding: Cp1252
net.filebot.AcoustID.fpcalc: D:\Program Files\FileBot\lib\fpcalc.exe
net.filebot.UserFiles.fileChooser: COM
org.apache.commons.logging.Log: org.apache.commons.logging.impl.NoOpLog
os.arch: amd64
os.name: Windows 10
os.version: 10.0
path.separator: ;
prism.order: sw
sun.arch.data.model: 64
sun.boot.library.path: D:\Program Files\FileBot\jre\bin
sun.cpu.endian: little
sun.cpu.isalist: amd64
sun.io.unicode.encoding: UnicodeLittle
sun.java.command: D:\Program Files\FileBot\jar\filebot.jar -script fn:sysenv
sun.java.launcher: SUN_STANDARD
sun.java2d.d3d: false
sun.jnu.encoding: Cp1252
sun.management.compiler: HotSpot 64-Bit Tiered Compilers
sun.net.client.defaultConnectTimeout: 10000
sun.net.client.defaultReadTimeout: 60000
sun.os.patch.level:
sun.stderr.encoding: cp850
sun.stdout.encoding: cp850
swing.crossplatformlaf: javax.swing.plaf.nimbus.NimbusLookAndFeel
unixfs: false
useCreationDate: false
useExtendedFileAttributes: true
useNativeShell: false
user.country: DE
user.dir: C:\Windows\System32
user.home: C:\Users\scherzeking
user.language: de
user.name: scherzeking
user.script:
user.timezone: Europe/Berlin
user.variant:

# Arguments #
args[0] = -script
args[1] = fn:sysenv
Done ?(?????)?
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: -exec command bugged after version 5.0.3

Post by rednoah »

scherzeking wrote: 31 Dec 2023, 13:47 I usually collect several folders and drag and drop the folder into a .bat file. After a few more tests, I've figured out that the problem is somewhere in the parameters I have. Without them the command works fine. How can I set the correct behavior so that the first parameter after -exec is the batch file to run via cmd and the rest are parameters for this test.bat file? Again, this worked with 5.0.3.
I see. So you have a *.bat script that uses parameters like %1 to %* and then passes them on to a filebot command. That's important context.


:?: So changes in your *.bat file can make it work or not work? Please post your *.bat file, or at least an "as simple as possible" test.bat script that we can use for testing.


:!: Windows CMD and BAT are really weird. The more you use it, the more you will run into strange behaviours, that's why we all avoid BAT scripts to the extent possible. If you find strange behaviours, the best you can do is do trial & error until you figure it out. Once we figure it out, we'll have a laugh and curse the BAT developers from 35 years ago. It's a New Years custom in many parts of the world. :lol: :roll:
:idea: Please read the FAQ and How to Request Help.
scherzeking
Posts: 10
Joined: 16 Dec 2021, 21:39

Re: -exec command bugged after version 5.0.3

Post by scherzeking »

Ye, I know I'm one of those people, who uses batch files xD
I think it's not a batch file problem. Something changed in the -exec command, because the test.bat was the same as yours above. Can you not reproduce it with the command above (The Simple test command and output)?

If you really want something I've used in my real batch file here it is:

the drag and drop folder on batch file:

Code: Select all

@echo off
SET input=%1
SET output="Z:\Output Serien"
SET "inputNEW=%~1"
SET "inputNEW=%inputNEW:&=^&%"

filebot -rename -r %input% --format "{n} ({y})/{episode.special ? 'Specials' : 'Season '+s}/{episode.special ? 'S00E'+special.pad(2) : s00e00} - {t.take(128)}{ subt }{ if (f.subtitle) '(' + fn.match(/_(\d{1,2})$|\((\d{1,2})\)$|^(\d+)_/) + ')' }" --db TheTVDB --lang German --mode interactive -non-strict --apply import --output %output% -exec "Z:\Input Serien\test.bat" "{folder}\{historic.f.dir.name}"
pause
the test.bat

Code: Select all

@Echo Off
if not exist %1 mkdir %1
output

Code: Select all

Rename episodes using [TheTVDB] with [Airdate Order]
Fetching episode data for [Alias]
* Alias - Die Agentin [75930] | 105 episodes | 1x01-22 .. 2x01-22 .. 3x01-22 .. 4x01-22 .. 5x01-17
[MOVE] from [Z:\Input Serien\Alias\Alias - S01E01.mkv] to [Z:\Output Serien\Alias - Die Agentin (2001)\Season 1\S01E01 - Tödliche Wahrheit.mkv]
[MOVE] from [Z:\Input Serien\Alias\Alias - S01E02.mkv] to [Z:\Output Serien\Alias - Die Agentin (2001)\Season 1\S01E02 - Neuanfang.mkv]
Der Befehl "Z:\Input" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
[C:\WINDOWS\system32\cmd.exe, /c, Z:\Input Serien\test3.bat, Z:\Output Serien\Alias - Die Agentin (2001)\Season 1\Alias] failed (1)
Processed 2 files
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: -exec command bugged after version 5.0.3

Post by rednoah »

:?: What happens if we add some debug logging to the script?


test.bat

Code: Select all

echo "BEGIN test.bat"
echo "Parameter 1 = %1"
if not exist %1 mkdir %1
echo "END test.bat"

:idea: If have reason to believe that your script might be successfully called by filebot, your script then calls mkdir which then prints Der Befehl "Z:\Input" ist entweder falsch geschrieben oder konnte nicht gefunden werden. to console output and fails with exit code 1 for some reason.
:idea: Please read the FAQ and How to Request Help.
scherzeking
Posts: 10
Joined: 16 Dec 2021, 21:39

Re: -exec command bugged after version 5.0.3

Post by scherzeking »

Nothing changes with the output with your suggestion.
rednoah wrote: 31 Dec 2023, 15:34:idea: If have reason to believe that your script might be successfully called by filebot, your script then calls mkdir which then prints Der Befehl "Z:\Input" ist entweder falsch geschrieben oder konnte nicht gefunden werden. to console output and fails with exit code 1 for some reason.
I think the issue is not the test.bat file. Even if I don't use any parameters in that file with %1 %2 etc. the error is the same. The -exec trys to execute the second parameter "{folder}\{historic.f.dir.name}", which fails. Is there a way to declare this as a parameter used for the test.bat file and not to execute it again with a new cmd.
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: -exec command bugged after version 5.0.3

Post by rednoah »

This line in the console output:

Code: Select all

[C:\WINDOWS\system32\cmd.exe, /c, Z:\Input Serien\test3.bat, Z:\Output Serien\Alias - Die Agentin (2001)\Season 1\Alias] failed (1)
means that FileBot is trying to execute this command:

Code: Select all

"C:\WINDOWS\system32\cmd.exe" /c "Z:\Input Serien\test3.bat" "Z:\Output Serien\Alias - Die Agentin (2001)\Season 1\Alias"
This looks good to me at a glance. filebot executes cmd which then executes test3.bat. I don't see anything that can go wrong here.


i.e. Execute C:\WINDOWS\system32\cmd.exe and pass arguments:

Code: Select all

1: /c
2: Z:\Input Serien\test3.bat
3: Z:\Output Serien\Alias - Die Agentin (2001)\Season 1\Alias

I'm not using Windows at the moment, so I can't easily run lots of tests.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: -exec command bugged after version 5.0.3

Post by rednoah »

:!: Looks like cmd /c fundamentally doesn't (always) do what I think it does:

Code: Select all

X:\>cmd /c "C:\Program Files\FileBot\filebot.exe" -version
FileBot 5.1.2 (r10125)

Code: Select all

X:\>cmd /c "C:\Program Files\FileBot\filebot.exe" "-version"
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
I have no idea how these two commands could behave differently. That's just BATshit crazy...


:idea: Using call somehow makes things work as expected:

Code: Select all

X:\>cmd /c call "C:\Program Files\FileBot\filebot.exe" "-version"
FileBot 5.1.2 (r10125)

:?: So this will probably work:

Shell: Select all

-exec call "Z:\Input Serien\test.bat" "{folder}\{historic.f.dir.name}"

:?: If you happen to figure out why cmd does what it does in some docs somewhere, do let me know.



EDIT:

https://stackoverflow.com/a/73470776/1514467 has some explanation as to why cmd behaves differently depending on the arguments.



EDIT 2:

FileBot r10169 removes cmd /c usage because it clearly does more harm than good in terms of introducing unexpected inconsistent behaviours. %PATH% resolution can be done by FileBot itself head of time. CMD built-in commands and custom %PATHEXT% executables will no longer work though.
:idea: Please read the FAQ and How to Request Help.
scherzeking
Posts: 10
Joined: 16 Dec 2021, 21:39

Re: -exec command bugged after version 5.0.3

Post by scherzeking »

With "call" it works again. Thank you very much. I knew filebot had changed something, but could not find it.
I have no idea why cmd and batch files behave this way. I had too many headaches to make it work in the first place. So I don't want to rewrite everything. I'm glad I can leave it as it is. You can close the thread, if you want to.

Oh, and Happy New Year btw.
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: -exec command bugged after version 5.0.3

Post by rednoah »

Cheers and HNY~


:idea: Keep in mind that r10169 and up will no longer require the call workaround, and call will likely no longer work since it's a CMD built-in, so after the next update you can go back to just having Windows execute the *.bat file directly.
:idea: Please read the FAQ and How to Request Help.
Post Reply