Batch file to open the cmd prompt and execute - batch-file

can any one help me in this.
I want to run the cmd prompt through Bat file.
#echo off
cd ..
cd ..
dir /b w:\0*.jpg >abc.csv
pause
The above code collect all .jpg from w drive and will store in C drive as abc.csv

Is it not simply?
#echo off
cd ..
cd ..
dir /b w:\0*.jpg >abc.csv
start cmd || ::This line opens a new prompt.
pause

Related

Batch file console not stopping to display the output

I'm trying to execute a batch file but its console is not stopping for its output.
here's the code:
goto D:
cd postgresql-9.6.0-1-windows-x64-binaries
cd pgsql
cd bin
start pg_ctl start -D D:\pg_data\data
#echo on
echo server started
pause
I am assuming it is on the D: drive. use cd /d see cd /? for the reason why.
#echo off
cd /d "D:\postgresql-9.6.0-1-windows-x64-binaries\pgsql\bin"
start "" "pg_ctl" start -D "D:\pg_data\data"
echo server started
pause
change to start "" /wait if you want to wait for the service to start before you echo it has been started.

echo multiple lines with CMD to .bat file

I need to use CMD to echo these lines :
#ECHO OFF
cd C:\Program Files (x86)\Atelier Web\Remote Commander Pro\
awrcp.exe /r=test
goto end
:end
to .bat file
Well remove echo off. Really.

Insert text into cmd prompt through .bat file.

Any idea on, how to insert text into a new cmd prompt window to continue the script?
e.g.
runas /user:adminuser cmd
opens up new cmd window. I want to insert the below using the batch file
c:
cd\temp\file\executefile.exe
del c:\temp
Create a batch file "C:\batch.bat" and insert these commands in each line
c:
c:\temp\file\executefile.exe
del c:\temp
and start this batch file using following command
C:\> runas /user:adminuser C:\batch.bat
also you probably want to use following command to delete temp folder along with subfolder and files in temp. For that instead of del c:\temp use echo y | rmdir /s c:\temp in batch file
To print this on new windows cmd use this:
text.cmd:
#echo off
echo c:
echo.
echo cd\temp\fichier\executefile.exe
echo.
echo del c:\temp
pause
and use the command:
start text.cmd
You can use a file.cmd or file.bat it is the same.
runas /user:adminuser "cmd /C c: & cd\temp\file\executefile.exe & del c:\temp"
Previous line execute the commands and terminate the new cmd prompt window. If you want that the window remain after execute the commands, change /C by /K.
To insert manually values into your command prompt when executing a batch script, use the following:
set /p var=
echo %var%
This will gather what you entered, then display it (or wathever you need).

batch script to open an command window and run directory scan

I'm trying to create a batch script which opens a
1) command window
2) get the command prompt pointing to c (come to root)
3)run dir /s command which performs an extensive scan of the system starting from the root.
The window should not dissapear.
but i' m only able to come to come to c prompt and the command window disappears, i have posted the script here . Please let me know where exactly i'm going wrong .
start cmd /c cd / && dir /s
EDIT : The issue is fixed
ANSWER
start cmd /c
cd / && dir /s
You can use cmd with the /k switch to pass in your commands, such as:
cmd /k "pushd C: & cd\ & dir /s"

create a folder name variable dos command

i want to create a batch file
#echo off
set /p name="Type folder name(s):
md %name%
cd p:\%name%
all lines work, but i cannot change the directiory to cd p:\%name% when i run the script
thank you.
You need cd /d to change to a directory on another drive:
cd /d p:\%name%

Resources