I want to start a browser (Chrome, in this case) and open a page that is located on my computer, then continue executing other commands. Right now I have this:
#echo off
if exist "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" (
cmd /C "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "%cd%\MyPage\index.htm"
)
:: More commands here
pause
exit
And of course, it says the syntax is incorrect. I am stuck here and I don't know how to do it. It would also be great to open the same file in the same tag if I execute the batch multiple times (instead of opening a new tab each time) but I don't know if Chrome, at least, has this command available. Yet, for now the problem is that I cannot run the browser "asynchronously" and move to the next command in the batch file.
Get rid of the cmd /C
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -- "%cd%\MyPage\index.htm"
Chrome's open format can be found here HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command
Replaced cmd /c with start ""
#echo off
if exist "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" (
start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "%cd%\MyPage\index.htm"
)
:: More commands here
pause
exit
Related
So basically im trying to making a batch script which renames the directory
"C:\Program Files (x86)\Steam\steamapps\common\SteamVR"
to
"C:\Program Files (x86)\Steam\steamapps\common\SteamVRa"
it switches to SteamVR when enabled and SteamVRa when disabled (this is a segment of the full code)
here is what i cant figure out
after the following code is ran
cd /C "C:\Program Files (x86)\Steam\steamapps\common\SteamVRa"
rename "C:\Program Files (x86)\Steam\steamapps\common\SteamVRa" "SteamVR"
timeout 1 >nul
if exist "C:\Program Files (x86)\Steam\steamapps\common\SteamVRa" (
echo Unknown Error
) else (
echo Steam Vr is Enabled, finished
)
if theres any errors not relating to this or ways the code can be better feel free to mention it as well im not very good with batch files
It comes up with the error "The filename, directory name, or volume label syntax is incorrect."
But directly after that it then says "Steam Vr is Enabled, finished"
cd /C "C:\Program Files (x86)\Steam\steamapps\common\SteamVRa"
Is invalid and generating that message.
There is no /c option to cd.
The /d option would switch your current directory to "C:\Program Files (x86)\Steam\steamapps\common\SteamVRa"
If you change /c to /d you will get another error (The process cannot access the file because it is being used by another process.) The "other process is itself.
If you remove the cd altogether, the process works happily.
To recreate my problem you need to understand that I have next files in 2 folders.
K:\Script.bat
K:\Project\PortChanger.exe
K:\Project\settings.xml
I want to launch PortChanger.exe using Script.bat that contains next line:
start "K:\Project\PortChanger.exe"
This script is actually executing Program.exe, but my program throws me exception since PortChanger.exe can't find Settings.xml.
How can I launch PortChanger.exe from "K:\Project\", not from "K:\"? Now it seems like .BAT taking .EXE code and just running it where .BAT is locating.
To make it even more clear:
You could use Start with its /D option:
Start "" /D "K:\Project" "K:\Project\PortChanger.exe"
Open a Command Prompt window and enter start /? to read its usage information.
I would suggest you rather use pushd and popd
#echo off
pushd "K:\Project"
start "" PortChanger.exe
popd
pushd will change to the directory, launch the executable from it, then popd will return to the previous directory stored.
I'm currently working on a batch file that should download files via their URL and them run formatting script on them however I don't know how to to delay the batch-file during downloading, however since it's a direct download the window doesn't stay open.
here's where I'm at :
START "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://www.oui.oui.fr/oui
MOVE C:\\Users\\*\\downloads\\*.csv %~dp0
EXIT
I would like to wait for the first line to finish before continuing.
Thanks for your consideration
From cmdline (cmd.exe) run start /? and you will find some help. There is a specific line in the help file for the /wait switch which reads:
WAIT Start application and wait for it to terminate.
So simply start chrome with the /wait switch:
Start /wait "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://www.oui.oui.fr/oui
As per your comment, the above will not work. It is probably best to test if the file exists, chrome will have a .crdownload extension when still downloading. So let's test that the *.csv.crdownload does not exist.
start /wait "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://www.oui.oui.fr/oui
:hold
timeout 5
if /i not exist *.csv.crdownload (MOVE "C:\\Users\\*\\downloads\\*.csv" %~dp0) else ( goto :hold)
exit
I combined a couple of solutions I found online to try and make this happen.
https://stackoverflow.com/a/6504317/2471473
https://sqlandme.com/2013/03/25/sql-server-executing-multiple-script-files-using-sqlcmd/
I'm trying to run a single .cmd script (Script1.cmd) with folder locations of .sql files. That single script runs another script (Script2.cmd) to use sqlcmd to execute all the .sql files in that folder location. It mostly works, but it leaves a command window open that I have to exit from for each folder location.
Script1.cmd
start Script2.cmd "C:\Location1"
start Script2.cmd "C:\Location2"
Script2.cmd
#Echo Off
FOR /f %%i IN ('DIR %1\*.Sql /B') do call :RunScript %1 %%i
GOTO :END
:RunScript
Echo Executing Script: %2
cd %1
SQLCMD -S Server123 -d Database456 -E -i %2
Echo Completed Script: %2
:END
Official command line reference for Windows XP or for Windows Server 2003, Windows Vista (and above) seems to be too brief. Read this (extended) start command documentation:
Syntax: START "title" [/D path] [options] "command" [parameters]
Always include a TITLE this can be a simple string like "My Script" or
just a pair of empty quotes "". According to the Microsoft
documentation, the title is optional, but depending on the other
options chosen you can have problems if it is omitted.
If command is an internal cmd command or a batch file then the command
processor is run with the /K switch to cmd.exe. This means that the
window will remain after the command has been run.
Next Script1.cmd should work and close started command windows:
start "" cmd /C Script2.cmd "C:\Location1"
start "" cmd /C Script2.cmd "C:\Location2"
I want to write a batch file that will do following things in given order:
Open cmd
Run cmd command cd c:\Program files\IIS Express
Run cmd command iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
Open Internet Explorer 8 with URL= http://localhost:8088/default.aspx
Note: The cmd window should not be closed after executing the commands.
I tried start cmd.exe /k "cd\ & cd ProgramFiles\IIS Express", but it is not solving my purpose.
So, make an actual batch file: open up notepad, type the commands you want to run, and save as a .bat file. Then double click the .bat file to run it.
Try something like this for a start:
c:\
cd c:\Program files\IIS Express
start iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
start http://localhost:8088/default.aspx
pause
I think the correct syntax is:
cmd /k "cd c:\<folder name>"
This fixes some issues with Blorgbeard's answer (but is untested):
#echo off
cd /d "c:\Program files\IIS Express"
start "" iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
timeout 10
start http://localhost:8088/default.aspx
pause
cmd /c "command" syntax works well. Also, if you want to include an executable that contains a space in the path, you will need two sets of quotes.
cmd /c ""path to executable""
and if your executable needs a file input with a space in the path a another set
cmd /c ""path to executable" -f "path to file""
#echo off
title Command Executer
color 1b
echo Command Executer by: YourNameHere
echo #################################
: execute
echo Please Type A Command Here:
set /p cmd=Command:
%cmd%
goto execute
start cmd /k "your cmd command1"
start cmd /k "your cmd command2"
It works in Windows server2012 while I use these command in one batch file.
cmd /k cd c:\
is the right answer
I was trying to run a couple of batch files parallely at startup, if a condition was true.
For this I made a parent batch file which should have checked for the condition and invoke the other child batch files if the condition was true.
I tried to achieve it via START but it gave me an empty black command prompt running in the directory of children batch files, instead of running the children batch files themselves
The thing which worked for me was by using a combination of START and CALL
As an example
condition ...
start call "C:\Users\Amd\conn\wsl_setup - conn1.bat"
start call "C:\Users\Amd\conn\wsl_setup - conn2.bat"
start call "C:\Users\Amd\conn\wsl_setup - conn3.bat"
I know DOS and cmd prompt DOES NOT LIKE spaces in folder names. Your code starts with
cd c:\Program files\IIS Express
and it's trying to go to c:\Program in stead of C:\"Program Files"
Change the folder name and *.exe name. Hope this helps