I am writing a batch file for the gdb debugger.
I run the gdb process but I want to know how to pass the parameters to the gdb process from the batch file.
Here is my sample batch file:
#echo off
cd /d "c:\MinGW\bin\"
set PATH=c:\MinGW\bin\
echo %PATH%
gcc -g start.c -o start.exe
gdb start.exe
gdb > set logging file output.txt
gdb > b 1
pause
As shown above when I start gdb for start.exe, I need to pass the set logging file and breakpoint parameters to it via the batch file. But above code is not working. Please help me on this.
Related
I want to execute an executable along with it's parameters from a Batch file silently without printing anything on the console from the executable and the executable shouldn't be executed from another console(it shouldn't open another command-prompt to execute). For that I tried with start command as following and couldn't execute it.
start "C:\myApp.exe -mode='a' -inputFilePath='%filePath%'" -i silent
Where %filePath% is a variable and -mode,-inputFilePath are the arguments to my executable.
Please correct me for anything wrong in above statement and help me out in this. Thanks!
From your batch file, just execute the following:
C:\myApp.exe -mode='a' -inputFilePath='%filePath%' >NUL
the >NUL redirects the output to nothing for that command.
I wrote a batch called pippo.bat for launching a program with an argument. However, it fails in getting such argument. In other words, it acts as I don't give it any argument.
pippo.bat
#echo off
mode con: cols=150 lines=5000
title Link Setting
echo.
echo LINK SETTING
echo.
cd /d E:\Program Files (x86)\pippo\bin
pippoedit.ovpl –f C:\Work\pippo.xml
pause
What's wrong?
You're executing pippoedit.ovpl –f C:\Work\pippo.xml.
Note the extension, .ovpl, which isn't registered as an executable. This means you let the OS figure out and start the application associated with that extension, and start that program with that filename as argument. Here, a small repro:
#echo off
foo.txt bar.txt
This starts Notepad or whichever application is associated with the .txt extension and displays the file foo.txt.
When you do this, Windows doesn't do anything with the arguments beyond the first. Instead you should start the application directly, and pass it the arguments:
pippoedit.exe pippoedit.ovpl –f C:\Work\pippo.xml
Or whatever the executable is called.
I have multiple versions of a program called Siemens NX. NX uses environmental variables for configuration. I need NX 10.0 to use a different set of environmental variables than my NX 7.5 which uses the system environmental variables. Therefore, I have written a batch file that setups the environmental variables that I need. However, There is a lot of different programs that go with NX 10.0. I don't want to have to create a batch file for each program. Instead, I just want to ammend the shortcuts (.lnk) to execute a batch file before starting. For instance, this is easily done by
C:\Siemens\NX10\UGII\setup_NX10_environment.bat && C:\Siemens\NX10\UGII\ugraf.exe -nx
However, the command window is left open. How can I call the batch script and it closes and then calls my program?
Supply program with parameters to your batch script as follows
C:\Siemens\NX10\UGII\setup_NX10_environment.bat "C:\Siemens\NX10\UGII\ugraf.exe" -nx
and improve that batch as follows:
rem all the original setup_NX10_environment.bat stuff here
%*
exit
or
rem all the original setup_NX10_environment.bat stuff here
call %*
exit
or
rem all the original setup_NX10_environment.bat stuff here
start "" %*
exit
The console window may remain open if you call the executable like this:
executable.exe
However, prepending start to the executable will detach it from the console.
Thus the console will not remain open if you call the executable like this:
start executable.exe
In conclusion, rewrite your command as follows:
C:\Siemens\NX10\UGII\setup_NX10_environment.bat && start C:\Siemens\NX10\UGII\ugraf.exe -nx
I am using a make.bat file to compile my Fortran code. To compile using the ifort command, I first need to initialize the compiler by executing ifortvarsbat intel64 command where I had to setup the path variable.
This works fine, however, the path keeps increasing in size and says command too long after 3-4 runs. Now, I open a command prompt, run the make.bat file once and then comment the ifort setup section so my successive run of the make.bat do not set the path multiple times.
I was hoping I could write an IF ELSE command to check whether ifort command executes or not and only set the path and call ifortvars if its not already set. This would save me commenting and uncommenting the make.bat file every time I open a new command prompt.
Unfortunately, I don't know much about batch script writing. Can someone help me with this.
#echo on
#echo ==============================================
#echo Setting Intel Fortran Compiler, please wait ...
#echo ==============================================
::set MY_PATH=C:\Program Files (x86)\Intel\Composer XE 2013\bin
::call "%MY_PATH%"\ifortvars.bat intel64
::call "%MY_PATH%"\ifortvars.bat ia32
#echo ==============================================
#echo Compiling program:
#echo ==============================================
:: -O3 option is used to optimize the code
ifort -O3 "Main.F90"
Instead of checking the path variable, directly check if the compiler is available
where ifort >nul 2>&1 || call "%MY_PATH%\ifortvars.bat" intel64
where command will search for the indicated program inside the path and if found it echoes to console its path. If it does not find the program it echoes an error and sets errorlevel variable.
In the code all the output from where is hidden redirecting the stdout and stderr streams to nul device (>nul 2>&1) and conditional execution is used. The || operator means "execute the following command if the previous one failed"
So, if ifort can not be found then call the configuration batch.
A faster solution could be to directly check a "flag" variable that you define the first time the environment is configured.
if not defined FCompilerSetup (
call "%MY_PATH%\ifortvars.bat" intel64
set "FCompilerSetup=1"
)
note: From my point of view, the recomendation from miltonb and i_am_jorf is the correct way to handle the problem. setlocal / endlocal will remove the problem with the path and is cleaner and easier. But the batch file to set the environment will be called each time you compile your program and the changes removed on end. If any of the changes made to the environment is needed after compilation, it will not be available.
Using setlocal will not change your path beyond the scope of the batch file, so that when it runs again it will modify the path again.
Before running: PATH=C:\Mypath;
setlocal
::set MY_PATH=C:\Program Files (x86)\Intel\Composer XE 2013\bin
....other lines....
endlocal
After running: PATH=C:\Mypath;
I'm trying to run several background processes from a batch file and have the output directed to a file. Is it possible to do this in Windows? This is what I've tried but it end up directing the output of the start program rather then background process.
start myapp.exe > myapp.out 2>&1
Actually it is quite easy without using a helper batch file. You just need to run the application via cmd.exe instead, and make sure to escape the special characters so they pass through to cmd.exe.
You probably don't want to see an extra console window, so use the START /B option.
start /b "" cmd /c myapp.exe ^>myapp.out 2^>^&1
Each STARTed process must have its output directed to a unique file. Multiple processes cannot share the same output file.
I think the only chance you have is to create one batch file for each exe that you want to start. Inside the batch file you can redirect the output. The master batch file would then "start" the batch file, not the exe directly.
You just need to include an exit command at the end of each batch file:
start_myapp.cmd contains the following:
myapp.exe > myapp.out 2>&1
exit
then you can run
start start_myapp.cmd
and the output will be redirected