I'm trying to write the first argument of a command line in a file, but it works in command line and not with drag and drop.
The very simple batch file (test_echo.cmd
) is as following:
@echo OFF
echo %1 > echo_arg_in_file.txt`
On the command line,
C:\rep>test_echo.cmd "C:\rep\fichier de test.txt"`
creates a file echo_arg_in_file.txt
with "C:\rep\fichier de test.txt"
written inside.
But with a drag and drop of the file "C:\rep\fichier de test.txt"
on the batch file, nothing happens... (the test to delete > echo_arg_in_file.txt
was done before and displays well "C:\rep\fichier de test.txt"
)
Any explanation?
I'm not sure about your precise environment, but if I have to bet, current active directory is the problem
Replace your
test_echo.cmd
withThen execute the file both by double clicking it and by drag/drop a file. In both cases you will see the current active directory for the started
cmd
process.Why is this relevant? As you have not included a path in the original file redirect, this file will be created in the current active directory that, maybe, could not be what you expect.
You can find more information here
For a quick solution,
that will create the file in the same folder that hold the batch file