I would like to save JPG into the same folder as RAW file is, but %~dpnx1 is not working for output.
In fact I need to replace c:\darktable_export\ by path of the source file.
Depending on the shell used you might have to escape the $ to become \$. It might also be that the version you tried would work if you used \\ or / as path separators.
@P_Cherry My go-to reference is Parameters / Arguments - Windows CMD - SS64.com. In CMD.exe command line, you use single %s, but in batch files, you need to double them %%. If this is the only command you are doing, I suggest that you use a for loop directly in CMD:
for %i in (*.CR2) do darktable-cli %i %i.xmp %~ni.jpg