Cannot start .exe file propetly because config - batch-file

So...I have "launcher"..
Its .bat file and i want it to start /ffa/server.exe
but..In ffa/ i have config file.
When i start server via launcher it starts server but it makes new config file
in directory of launcher..How can i fix this?
And "server" its: https://github.com/OgarProject/Ogar
start cmd /k %~dp0\ffa\server.exe
Please help me, its really frustrating..Thanks <3!

You can use pushd to move to the correct directory, start the server, and then pop back:
pushd %~dp0\ffa
start cmd /k server.exe
popd
I'm not familiar with the exact folder structure you're working with, and exactly how you call the script, but you definitely could use push/popd for this.

There are more possible solutions to change working directory of started command prompt window:
In calling script
pushd %~dp0\ffa
start "" cmd /k server.exe
popd
In started cmd itself: note properly escaped & character (see redirection)
start "" cmd /k pushd %~dp0\ffa^&server.exe
Using /D parameter of start command
start "" /D "%~dp0\ffa" cmd /k server.exe

Related

many start commands batch in the same window

I would like to start 3 commands in the same window.
For now I have this batch but there are 3 different windows at each command.
start /d "c:\Program Files\myfolder" cmd /k cscript A
timeout /t 6 >nul
start /d "c:\Program Files\myfolder" cmd /k cscript B
timeout /t 6 >nul
start /wait /d "c:\PProgram Files\myfolder" cmd /k cscript C
What should I modify to have only one window? thanks
I think you can run a .bat file by changing the directory like so, cd C:\PATH\TO\DIRECTORY\WITH\FILE, then use call (file name here). This should work assuming that all the files are in the same directory, if not you'll just have to change the directory for each call method. If my code doesn't seem very helpful, check this page out https://superuser.com/a/1062322
Example Code
#echo off
cd PATH\TO\FILE\DIRECTORY
call FILE NAME
echo The file (file name here) has run!
pause
this code will make a call to the file and pause the terminal to keep it opened. You can take this code and make as many calls/cd's as you like. I hope this helped, If it doesn't work, please tell me what doesn't work and I'll try to fix it. Have a nice day :)

How to make a batch file that lets you use cmd after?

what I'm essentially trying to do is make a batch file (or shortcut if possible) to change to a directory, echo a message, and then let you use the cmd window as if you had opened it up normally after.
Example:
The batch file/shortcut opens a cmd prompt in C:\test-folder\
Echos "This is your message"
Awaits user input for commands
I've tried the following command:
start cmd /k cd /d C:\test-folder\
echo test
The folder change will work without the echo line, but if I include the echo line, it will not work at all.
Is there any way to do what I'm trying to accomplish here?
the order of the switches matters. See start /? and cmd /? for details.
start "My window" /d "d:\" cmd /k "echo Hello&echo use me"
"My window" belongs to start and gives the new window a title.
/d "c:\test-Folder\" also belongs to start and gives the startdirectory
cmd is the command to start
/k belongs to cmd and has to be cmd's (only or) last Switch
"echo Hello&echo use me" is the commandline to execute.
Your problem is the echo test is run in the parent window that issues the START command. You want the ECHO to occur in the window that START launches.
One option is to append the ECHO command to the end of the START command, remembering to escape the & so that it is included as part of the CMD /K option.
start cmd /k cd /d C:\test-folder\ ^& echo test
Or you could put quotes around the entire /K option (CMD will remove the quotes before executing the string):
start cmd /k "cd /d C:\test-folder\ & echo test"
Or you could use Stephan's suggestion to let START set your active directory, so that your CMD /K option only needs to ECHO the message.
start /d "C:\test-folder" cmd /k echo test
Or you can create a shortcut and edit the properties such that
"Target" = C:\Windows\System32\cmd.exe /k echo test
and
"Start in" = c:\test-folder
If you create a batch file that ends with cmd /k, it will run the commands before cmd /k and then leave you in a command prompt. This is useful if you're performing enough work that makes a one-liner shortcut hard to write.
To get the behaviour you described, you can create a file called "open_test_folder.cmd" with the following:
#echo off
cd C:\test-folder
echo This is your message
cmd /k

cmd or bat run commands within file

This might be very basic but I cannot find the answer in the internet.
I have a cmd/bat file with 3 basics lines to set the working directory as the one of the current folder.Once I run it, I get the CMD window, and I type specific commands (example : "start notepad").
%~d1
cd "%~p1"
call cmd
What should I write within the cmd. or bat. file so the "start notepad" will be already launched as command?
Thank you very much
There are a couple of ways you can achieve this.
You can open notepad directly with the start command and then run cmd, like this:
#echo off
%~d1
cd "%~p1"
start "" notepad
call cmd
You can also include the notepad start command directly in the cmd call, like this:
#echo off
%~d1
cd "%~p1"
call cmd /k start "" notepad
Note that there is a "" after start because start considers the first set of quotes that it encounters to be the window's title.
Try this:
#echo off
Command.Com
When you'll open this batch file it will open up CMD where you can start typing commands like start notepad etc...I think this was what you was looking for?

How do I execute cmd commands through a batch file?

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

Execute multi command in batch

I tried to run multi-windows commands inside one opened window from a batch file.
I want the opened command window to perform two things in sequence:
Switch volume
Direct to a directory in that volume.
Here's what I wrote:
start cmd /k C: && cd 'C:\Program Files (x86)\aaa\'
However, this only switches volume. The second thing is not executed.
Can anyone please show me the way?
Well, you have at least 2 options...:
1st, make sure your && is passed to new cmd...
start cmd /k "C: && CD c:\temp"
2nd, use /d switch on cd to "get there" in one step...
start cmd /k cd /d c:\temp
KR
Bartek
What don't you just open your cmd at the needed directory? Like^
start /dc:\temp cmd
If you want to change directory to another drive you can use
cd /d C:\
but if your changing directory within the same drive you shouldn't need to switch drives, just change to that directory:
cd "C:\Program Files (x86)\aaa"
Remember to put quotes around paths with spaces, possibly why your command didn't work earlier.
Also, you shouldn't really need start and cmd. What you doing doesn't really need to be threaded as such. If it's a batch file you can just use pause at the end instead of using cmd /k.
Your complete batch file would then look like this:
cd "C:\Program Files (x86)\aaa"
pause >nul
or using cmd /k for one line (in case of command line use):
cmd /k cd "C:\Program Files (x86)\aaa"
Hope this helps!

Resources