I'm trying to write a batch file to act as an interface between Source-Insight, and Git running on a Linux server, but I'm running into an issue where the set /p does not seem to be working as advertised.
The batch file is supposed to run a linux script (via plink), which will check out the appropriate files into two directories, and then invoke Beyond Compare to compare the directories (note, these are on an sftp mounted drive so that dos can see them). The directory names are dynamic, so I need the batch file to read the generated directory name from a file before passing it to Beyond Compare. I can't seem to get this working...
I have the following lines in my batch script:
#echo on
plink server1234 -l %user% -i %ppk_file% "cd %root%; ~/bin/compare_git_all.sh --debug --ref"
echo "set /p dir=<%dosroot%\.comparegit.dosdir"
set /p dir=<%dosroot%\.comparegit.dosdir
echo dir="%dir%" (from %dosroot%\.comparegit.dosdir)
"C:\Program Files\Beyond Compare 4\BCompare.exe" %dir%.refpt %dir%
#echo off
My output ends up being:
"set /p dir=<z:\builddir\pd2\wt1\.comparegit.dosdir"
dir="" (from z:\builddir\pd2\wt1\.comparegit.dosdir)
So first issue (annoyance really), is that #echo on is not causing the commands to be echoed (which according to the pages I've google it's supposed to do...)
But what's killing me is that %dir% seems to be blank. I've verified that the file contains the data I am looking for:
C:\>more z:\builddir\pd2\wt1\.comparegit.dosdir
z:\builddir\pd2\wt1\.comparegit.zmP8BK
if I run the same command from a Command Prompt, I get:
C:\>set dir=blank
C:\>echo %dir%
blank
C:\>set /p dir=<z:\builddir\pd2\wt1\.comparegit.dosdir
C:\>echo %dir%
z:\builddir\pd2\wt1\.comparegit.zmP8BK
So, I'm missing something, but I'm not sure what it is. Any help would be appreciated. (note, if it makes any difference, the batch file is being invoked from a keymapping within Source Insight)
I need to write a batch script that pings google.com 30 times and then writes the output to a .txt file. here is the code I am currently using:
#echo off
:LOOPSTART
ping google.com -t >> filename.txt
goto LOOPSTART
Ping has an option to set the number of pings (see man ping)
ping -c 30 google.com > log.txt
or for windows I guess:
ping -n 30 google.com > log.txt
The option to submit custom numbers of pings to a host with ping is -n:
-n count Number of echo requests to send.
Your command would be:
ping -n 30 google.com
If you want to redirect this to a file, use the > operator.
However, in your example, you make a continuous loop, so you need to append it. This, can be done using the >> operator.
'Redirect', means to erase the previous content of the file (if the file exists), and write the output of the command there (if file doesn't exist, create a new file).
'Append' means to redirect the output of a command to a file without erasing the content of it.
You may choose which suits better for you, but I think you should use >>. Your code will be:
#echo off
:loopstart
(ping -n 30 google.com)>>filename.txt
goto loopstart
Read:
https://ss64.com/nt/syntax-redirection.html
Output of ping /? in cmd.exe.
I have automated file (.doc) uploads to an FTP server through BATCH files. I then run the BATCH file through the task scheduler every few minutes.
The below two batch files do the work for me:
upload.bat :-
open ftp.servername.com
username
password
cd FOLDER_NAME
binary
put D:\TEST\*.doc
bye
the above .bat file is called by the below .bat file,
startupload.bat :-
ftp -i -s:upload.bat
Now, the client removes files from the FTP once they are uploaded.
So, with above batch files, files are getting repeatedly uploaded.
Hence, my requirement is that each .doc file should be uploaded only once,
(OR,
may be, once a file is successfully uploaded to an FTP, it is shifted to another folder.)
Please help.
Thank you.
You can echo the directions into a text file then use -s?
Like the attached image
Then copy them to another folder and delete the originals?
#echo off
echo open serveraddress >ftp.txt
echo username>>ftp.txt
echo password>>ftp.txt
echo cd FOLDER_NAME>>ftp.txt
echo binary >>ftp.txt
echo "LCD D:\TEST\"
echo mput *.doc>>ftp.txt
echo bye>>ftp.txt
ftp -s:ftp.txt
del /f /q ftp.txt
copy "D:\TEST\*.doc" "C:\otherFolderPath\"
del /f /q "D:\TEST\*.doc"
::NOTES:
:: you can use ">>" to put the output of a command into a text file.
:: you can use ">" to put the output of a command into a text file. ">" Will clear a file if it exists, and will create a new file if it does not.
Note: If you want it to wait some time and then run again you can add this to the end of the script: Timeout /t 60 (That will wait 60 seconds, or until a user presses a key to continue)
I got this bat file from Stackoverflow that someone had posted back in 2014 but it will not output any info to the filename?
The file is created but without any info.....
can anyone please help, trying to record the ping output every 1 minute on a windows 7 machine.
#ECHO off
set IPADDRESS=192.168.0.1
set INTERVAL=60
:PINGINTERVAL
ping %IPADDRESS% -n 1 >> filename.txt
timeout %INTERVAL%
GOTO PINGINTERVAL
Your batch file is called ping.bat or ping.cmd and is calling itself. Rename the batch file or replace ping %IPADDRESS% ... with ping.exe %IPADDRESS% ...
The "echo off" is ok. This will only omit output from the script, not from the "ping" app.
I think the output is created in an unexpected location. Add the following lines at the beginning of the script to verify the current folder.
#echo %cd%
pause
Or simply specify the full path like so:
>> d:\fullpath\filename.txt
I want to learn how to write batch scripts and tried to create a script which automatically runs this command in the command line once:
ping www.google.de -t
and displays the ping, so it would look like this:
Reply from XXX.XXX.X.XX: time=30ms
Reply from XXX.XXX.X.XX: time=31ms
Reply from XXX.XXX.X.XX: time=29ms
My problem is, that this will result in this when I execute this command as script:
My problem is that it will not execute the ping command at all, but just insert the command unlimited times in the console window as its shown in the screenshot.
I just created a new file, wrote ping www.google.de -t in it, saved it as ping.bat file and executed it with double clicking on it.
So how to write the batch file to start this command only once and display the ping result?
I am sure you must have named the resultant bat file as "ping.bat". If you rename your file to something else say pingXXX.bat. It will definitely work. Try it out.
my batch file contains below code only
ping 172.31.29.1 -t
with file name as ping.bat
with file name abc.bat
Enter in a command prompt window ping /? and read the short help output after pressing RETURN. Or take a look on:
ping - latest Microsoft documentation for this Windows command
ping - Windows XP documentation for this Windows command
Explanation for option -t given by Microsoft:
Specifies ping continue sending echo Request messages to the destination until interrupted. To interrupt and display statistics, press CTRL+ENTER. To interrupt and quit this command, press CTRL+C.
You may want to use:
#%SystemRoot%\system32\ping.exe -n 1 www.google.de
Or to check first if a server is available:
#echo off
set MyServer=Server.MyDomain.de
%SystemRoot%\system32\ping.exe -n 1 %MyServer% >nul
if errorlevel 1 goto NoServer
echo %MyServer% is available.
rem Insert commands here, for example one or more net use to connect network drives.
goto :EOF
:NoServer
echo %MyServer% is not available yet.
pause
goto :EOF
For bash (OSX) ping google.com -c 1 (incase search brought you here)
if you want to use the name "ping.bat", a small trick is to use this code:
#echo off
cd\
ping google.com -t
Just add that "cd\" and you are fine... ;)
Not sure exactly what you are trying but your posted code should work just fine. in case you don't want the command to be displayed, add #echo off at starting of your script. If i have the below code in a file named as test.bat and run it command prompt as test.bat it will work just fine.
#echo off
ping www.google.de -t
To address your EDIT: where the main concern is ping command was not recognizable. ping command generally will be located under C:\Windows\System32\ where C:\ being the root directory. In case, the root directory is different you can get the root directory using %SystemRoot% environment variable and can say like
%SystemRoot%\Windows\System32\PING.EXE www.google.de -t
Another way to see if the command you are trying to run is recognizable or not is using WHERE command like below
where ping
If the command is recognizable; it will output the path like
C:\Windows\System32\PING.EXE
Else will result in error
I know why, you are using the file name "ping" and you are using the code "ping", it just keeps trying to run itself because its selected directory in where that file is, if you want it to actually ping, put this before the ping command: "cd C:\Windows\system32", the actual file that pings the server is in there!
From Batch file, ping a ip only once using the following command:
Ping 192.168.199.10 -n 1
i used Mofi sample, and change some parameters, no you can do -t
#%SystemRoot%\system32\ping.exe -n -1 4.2.2.4
The only thing you need to think about in this case is, in which directory you are on your computer.
Your command line window shows C:\users\rei0d\desktop\ as your current directory.
So the only thing you really need to do is:
Remove the desktop by "going up" with the command cd ...
So the complete command would be:
cd ..
ping XXX.XXX.XXX.XXX -t
Having 2 scripts called test.bat and ping.bat in same folder:
Script test.bat contains one line:
ping google.com
Script ping.bat contains below lines:
#echo off
echo Hello!
pause
Executing "test.bat" the result on CMD will be:
Hello!
Press any key to continue . . .
Why? Because "test.bat" is calling the "ping.bat" ("ping google.com" is interpreted as calling the "ping.bat" script).
Same is happening if script "ping.bat" contains "ping google.com". The script will execute himself in a loop.
Easy ways to avoid this:
Do not name your script "ping.bat".
You can name the script as "ping.bat" but inside the script use "ping.exe google.com" instead of "ping google.com".
Create a text file with text "#%SystemRoot%\system32\ping.exe -t www.google.com" and save it with extension ".bat".
Just click and run it and you will get the result.
So basically what happens is that we run ping.exe application with parameters '-t' and 'www.google.com' (web-address).
The answer to your question is this
Ping -n 1 0.0.0.0
But if you want it to be faster than this, this will be your answer
Ping -n 1 -l 1 0.0.0.0
Note: Replace 0.0.0.0 with your desired IP address
Just
write the command "ping your server IP" without the double quote. save file name as filename.bat and then run the batch file as administrator