I'm trying to make my Visual Studio build script execute a .bat file that does something important.
Active3 months ago
Create a SQL file containing select commands For e.g. Abc.sql having select queries in it 2. Create a bat file having following command: sqlplus abc.sql 3. Double click the bat file. Note: Output can be stored in an output file using SPOOL command in sql file. Add the below command in abc.sql before Select query to.
Here is what I'm want to do right now:
But it doesn't work.
I have to do this to make it work:
But this is pretty difficult to add to the Visual Studio script.
How can I do this in one single line?
Mofi
31.4k88 gold badges4242 silver badges9191 bronze badges
BingBang32BingBang32
4 AnswersBugs
4,20099 gold badges2727 silver badges3737 bronze badges
jwganjwgan
'F:- Big Packets -kitterengineCommonTemplate.bat' maybe prefaced with call (see call /? ). Or Cd /d 'F:- Big Packets -kitterengineCommon' & Template.bat .
CMD Cheat Sheet
CMD.exe
First thing to remember its a way of operating a computer. It's the way we did it before WIMP (Windows, Icons, Mouse, Popup menus) became common. It owes it roots to CPM, VMS, and Unix. It was used to start programs and copy and delete files. Also you could change the time and date.
For help on starting CMD type
cmd /? . You must start it with either the /k or /c switch unless you just want to type in it.
Getting Help
For general help. Type
Help in the command prompt. For each command listed type help <command> (eg help dir ) or <command> /? (eg dir /? ).
Some commands have sub commands. For example
schtasks /create /? .
The
NET command's help is unusual. Typing net use /? is brief help. Type net help use for full help. The same applies at the root - net /? is also brief help, use net help .
References in Help to new behaviour are describing changes from CMD in OS/2 and Windows NT4 to the current CMD which is in Windows 2000 and later.
WMIC is a multipurpose command. Type wmic /? .
Punctuation
Naming Files
Starting a Program
See
start /? and call /? for help on all three ways.
There are two types of Windows programs - console or non console (these are called GUI even if they don't have one). Console programs attach to the current console or Windows creates a new console. GUI programs have to explicitly create their own windows.
If a full path isn't given then Windows looks in
Specify a program name
This is the standard way to start a program.
In a batch file the batch will wait for the program to exit. Whentyped the command prompt does not wait for graphicalprograms to exit.
If the program is a batch file control is transferred and the rest of the calling batch file is not executed.
Use Start command
Start starts programs in non standard ways.
Start starts a program and does not wait. Console programs start in a new window. Using the /b switch forces console programs into the same window, which negates the main purpose of Start.
Start uses the Windows graphical shell - same as typing in WinKey + R (Run dialog). Try
Also program names registered under
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionApp Paths can also be typed without specifying a full path.
Also note the first set of quotes, if any, MUST be the window title.
Use Call command
Call is used to start batch files and wait for them to exit and continue the current batch file.
Other Filenames
Typing a non program filename is the same as double clicking the file.
Keys
Ctrl + C exits a program without exiting the console window.
For other editing keys type
Doskey /? .
Also not listed
17.6k3232 gold badges103103 silver badges170170 bronze badges
user6017774
There are many possibilities to solve this task.
1. RUN the batch file with full path
The easiest solution is running the batch file with full path.
Once end of batch file
Template.bat is reached, there is no return to previous script in case of the command line above is within a *.bat or *.cmd file.
The current directory for the batch file
Template.bat is the current directory of the current process. In case of Template.bat requires that the directory of this batch file is the current directory, the batch file Template.bat should contain after @echo off as second line the following command line:
Jul 19, 2019 Download AutoClicker for free. A full-fledged autoclicker with two modes of autoclicking, at your dynamic cursor location or at a prespecified location. The maximum amounts of clicked can also be set (or left as infinite). Auto clicker by polar download. Sep 14, 2019 OP Auto Clicker 15.1 (latest) OP Auto Clicker 9.2 OP Auto Clicker 6.1. No specific info about version 2.0. Info updated on: Sep 14, 2019. Related stories. Secret tricks with mouse clicks! Grand Theft Auto V For PC Postponed Once Again. Comments 4 comments. Notify me of replies from other users. Your vote: You. OP Auto Clicker is a automation tool that lets you automate mouse clicks. Perfectly compatible with Windows 7, Windows 8, Windows 10 and 64-bit systems.
Run in a command prompt window
cd /? for getting displayed the help of this command explaining parameter /D .. change to specified directory also on a different drive.
Run in a command prompt window
call /? for getting displayed the help of this command used also in 2., 4. and 5. solution and explaining also %~dp0 .. drive and path of argument 0 which is the name of the batch file.
2. CALL the batch file with full path
Another solution is calling the batch file with full path.
The difference to first solution is that after end of batch file
Template.bat is reached the batch processing continues in batch script containing this command line.
For the current directory read above.
3. Change directory and RUN batch file with one command line
There are 3 operators for running multiple commands on one command line:
& , && and || .For details see answer on Single line with multiple commands using Windows batch file
I suggest for this task the
&& operator.
As on first solution there is no return to current script if this is a *.bat or *.cmd file and changing the directory and continuation of batch processing on
Template.bat is successful.
4. Change directory and CALL batch file with one command line
This command line changes the directory and on success calls the batch file.
The difference to third solution is the return to current batch script on exiting processing of
Template.bat .
5. Change directory and CALL batch file with keeping current environment with one command line
The four solutions above change the current directory and it is unknown what
Template.bat does regarding
In case of it is important to keep the environment of current *.bat or *.cmd script unmodified by whatever
Template.bat changes on environment for itself, it is advisable to use setlocal and endlocal .
Run in a command prompt window
setlocal /? and endlocal /? for getting displayed the help of these two commands. And read answer on change directory command cd .not working in batch file after npm install explaining more detailed what these two commands do.
Now there is only
& instead of && used as it is important here that after setlocal is executed the command endlocal is finally also executed.
ONE MORE NOTE
If batch file
Template.bat contains the command exit without parameter /B and this command is really executed, the command process is always exited independent on calling hierarchy. So make sure Template.bat contains exit /B or goto :EOF instead of just exit if there is exit used at all in this batch file.
Community♦
MofiMofi
31.4k88 gold badges4242 silver badges9191 bronze badges
You Can Use Cmd Command To Run Batch File.
Here Is My Way =>
More Information =>
cmd /?
scientist_7scientist_7
Not the answer you're looking for? Browse other questions tagged windowscmdcommandprompt or ask your own question.
Active2 years, 8 months ago
I have a PowerShell script to add a website to a Trusted Sites in Internet Explorer:
I want to execute these PowerShell commands from a batch file. It seems simple when I have to run a single command, BUT in this case I have a sequence of related commands. I want to avoid creating a separate file for the PS script to be called from the batch - everything must be in the batch file.
The question is: How to execute powershell commands (or statements) from a batch file?
SteveC
7,1971919 gold badges7373 silver badges135135 bronze badges
AndreiAndrei
2,70522 gold badges1818 silver badges2424 bronze badges
5 Answers
This is what the code would look like in a batch file(tested, works):
Based on the information from:
Andrei
2,70522 gold badges1818 silver badges2424 bronze badges
Hassan VoyeauHassan Voyeau
2,17633 gold badges1818 silver badges2121 bronze badges
Type in cmd.exe Emiliano PoggiEmiliano Poggi
Powershell -Help and see the examples.
20.9k77 gold badges4646 silver badges6363 bronze badges
This solution is similar to walid2mi (thank you for inspiration), but allows the standard console input by the Read-Host cmdlet.
pros:
cons:
Commented and runable example of batch-ps-script.cmd:
Snippet for .cmd file:
kapitanrumkapitanrum
walid2miwalid2mi
Execute Batch File Command Line
Looking for the possibility to put a powershell script into a batch file, I found this thread. The idea of walid2mi did not worked 100% for my script. But via a temporary file, containing the script it worked out. Here is the skeleton of the batch file:
Batch File Execute Command One By One
eremmeleremmel
Execute Command Using Batch FileNot the answer you're looking for? Browse other questions tagged powershellcommand-linebatch-filepowershell-2.0 or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |