I think this is a pretty basic doubt but I could not find the solution myself. What I am trying to do is to create a .bat file in order to automate a data upload process. But the command to be passed in .bat file has to have database password which unfortunately has '%0' in it. So, when I run it, cmd reads it as the file name instead, causing it to run into an error. So, can we write this in a way cmd reads '%0' as it is and doesn't change it to filename?
Without seeing your code, it's guessing ...
Probably you are using something like
mysql -u root -p secret%0
Then you can fix it by doubling the percent sign
mysql -u root -p secret%%0
Related
I want to use a Batch file to upload files from a folder on my computer.
When I call the FTP Script to do the upload:
FTP -v -i -s:ftp.txt
or
FTP -v -i -s:c:\path\to\file\ftp.txt
Neither of those works, and instead
Error opening script file: ftp.txt
is returned.
Strange thing is, that the exact same script is being executed without problems on another computer.
Opening the batch file with admin-rights does not help. I'm running Windows 10.
Edit: The ftp.txt looks like this:
open ##host##
##user##
##password##
lcd c:\local\path\
cd path/on/server/
binary
mput "*.xxx"
disconnect
bye
Make a new, empty file with echo >ftp.test and try with that file.
If that gives you the same error, you'll need to look at your execution environment (look at set and the process owner of cmd.exe). It's also possible that the ftp command is being run as a user that doesn't have access to that file.
If you don't get an error then it's probably either a file-permissions or special-character issue with ftp.txt. Retyping the same content into a different file will get around those issues. Remember not to copy/paste because you could accidentally copy invisible special characters that you're trying to avoid.
I would like to add to this conversation since there have been a lot of views and no solution. I had the same response and it wasn't a permissions issue. It was also no the text file that was the issue because it never technically reached the text file. It was the path to the text file. The following for me didn't work. I had to put quotations around the path even though there were no spaces to confuse the command line.
What you tried:
FTP -v -i -s:c:\path\to\file\ftp.txt
What I tried and worked. (I didn't need to use -v, mine works without it)
FTP -i -s:"c:\path\to\file\ftp.txt"
Running the file acted normal for me. My issue was trying to run the batch file through Windows Task Manager. Somehow, this was causing it to lose the text file somehow. I hope this helps anyone else who reads this thread.
I had to put the .txt file path in the "Start In" section for it to work in Windows Task Manager. No problems since.
I have created a small script that initiates PSEXEC to run a file (a registry key) on a remote computer that is in the domain; however, when I run the script I receive an error indicating that "the system cannot find the file specified."
Below is my script:
#echo off
psexec \\PRECDP19425 -u PRECDP19425\WAKE -p <password> -h -i -d C:\Users\WAKE\Documents\AllowNetwork.reg
pause
I have double-checked the location to make sure I wasn't losing my mind and typed something incorrectly, yet that doesn't seem to be the case. The path is correct, I'm just not sure what is causing the script to fail.
The exact error I receive is:
PsExec could not start C:\Users\etc on PRECDP19425
The system cannot find the file specified.
Any help would be much appreciated.
C:\Users\WAKE\Documents\AllowNetwork.reg is not a valid command line because a .reg file is not an executable, you need to pass it to reg.exe:
REG IMPORT C:\Users\WAKE\Documents\AllowNetwork.reg
I am trying to write a simple batch file to run a MySqlDump. I created a new file in notepad, pasted the text below, and then saved it as a bat file. However when I attempt to run this in command prompt the screen pops up right away and then goes away just as fast. If I run these commands manually in command prompt it works as expected.
This is my first bat file I have created so I'm guessing I am doing something wrong? In looking at similar issues in StackOverflow the code below appears to be what is suggested so I'm confused why this isn't working?
cd C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin
mysqldump --user=xxx --password=xxx --all-databases --single-transaction > C:\Users\JMaze\Desktop\nSite\MySQL Backup\bk.sql
Adding the quotes to each of the file paths appears to have fixed the issue. The final code looks like this:
cd "C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin"
mysqldump --user=xxx --password=xxx --all-databases --single-transaction > "C:\Users\JMaze\Desktop\nSite\MySQL Backup\bk.sql"
I am vaguely familiar with batch. Super light knowledge. Anyways, I have this program that runs in a command line mode (it happens to render minecraft maps).
It is normally used by opening cmd, and typing mapcrafter.exe -c config.config -j 8 which runs the exe, specifies the config file, and runs the job with 8 threads.
One thing I wanted to do was put all of this in a batch file so I didn't have to type everything in every time I wanted to re-render it. It looked like:
start cmd.exe /K mapcrafter.exe --config "config.config" --jobs 8
This worked great, when the batch file was in the same directory as the exe.
Anyways, what I don't know how to do is to:
Start command prompt
change directory (cd) to the folder containing the .exe
Run the .exe with the two (-c -j) parameters
I want to do all of this in one batch file, and I want it to keep the command prompt window open, since the .exe outputs errors and percent completion.
I'm lucky I was able to get the one-line batch file working, with my limited knowledge of batch. At this point, I'm out of ideas as to how I should approach this. Thank you in advance for any help you can offer!
Why don't you just create a batch file with
mapcrafter.exe --config "config.config" --jobs 8
The reason it doesn't work when it is not in the same directory is because your path variable doesn't have the location of mapcrafter. An easier way around would be to use full path something like
D:\MineCraft\mapcrafter.exe --config "config.config" --jobs 8
If you want to learn more about configuring PATH environment variable see
Adding directory to PATH Environment Variable in Windows
you could just make a shortcut of the .bat file and have that on your desktop or wherever you want it. here is Microsoft's support page on this http://support.microsoft.com/kb/140443
I'm having some trouble and thought maybe someone could help me. This is what I have so far:
call date2.cmd
md %DT_MM%-%DT_DD%-%DT_YYYY%
cd %DT_MM%-%DT_DD%-%DT_YYYY%
psftp servername.com -P port -l username -pw pass -b script to run while in server
So, I run date2 which gives me the correct date output it starts psftp but stops there. I want to do an mget to grab all the files on the server and place them into the folder that I just created. If anyone can help steer me in the right direction that would be appreciated. I am sure I forgot some details, please let me know if there is any more information required.
(Untested)
Make a script called commands.txt and change your psftp line to actually use it:
psftp servername.com -P port -l username -pw pass -b commands.txt
Then put some test commands in the script and see what happens:
pwd
quit
or maybe
mget *
quit
I would recommend you use Putty plink.exe . I think it's much easier and it is scriptable and is able to handle or ignore prompting during the SSH session. Would also work on linux.