-1

I am trying to have an automatic batch file replace a file on my android device, it works when i type it in manualy but for some wierd reason it doesn't in the batch file.

Here is my code:

@echo off
echo Do you want to change the file?
echo 1)Yes

set /p choice= 
if %choice%==1 goto :change


:change
cd c:/
cd Users
cd Aidan
cd Desktop
cd My folder
cd platform-tools
adb devices
adb shell < change_file.txt

Then i have a remote file to run the commands, this is needed to run multiple commands is adb shell from a batch file.

Here is my change_file.txt :

su
cd storage
cd sdcard0
rm test.txt
cat > test.txt
test 
test
12345 test

In the command window it shows that it executes the commands several times and all it does it delete the file not replace it with a new one.

2

I got this one. Your cat listens for text, but... it keeps listening. You never signal the input termination, thus it doesn't create the file.

Instead of the following lines:

cat > test.txt
test
test
12345 test

use these:

cat << EOF > test.txt
test
test
12345 test
EOF

This will instruct cat to accept input until the End Of File is inserted, and will create your test.txt with the content of said input. Don't forget the EOF at the end of the input, or the behaviour will be the same as if you used your version of the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.