I know using External Tools options i can run a batch script or a cmd prompt. But here is what i need to do
I want to be able to call a dos prompt inside visual studio, which must be interactive. That way i won't be outside visual studio and can run all my dos commands in it. Is it possible? Or can i extend the command window and capture the commands which are typed and process them using my custom code?
Thanks
There's the Tools.Shell command which may work for you. You use the /c switch to specify that the output for the executable is displayed in the Command window. Then you call cmd.exe with /C switch which instructs it to close after finishing the command. For example if you type:
Tools.Shell /c cmd.exe /C dir C:
This will print the output to the Command window. Unfortunately, unlike the output, the input doesn't work. So if you type:
Tools.Shell /c cmd.exe /C pause
The prompt will not wait for your input (pressing a key).
If that's OK for you, you can even define an alias for most of this. For example you define alias sh for Tools.Shell /c cmd.exe /C:
alias sh Tools.Shell /c cmd.exe /C
Then you simply use it as follows:
sh dir c:
If you install NuGet, then it adds Package Manager Console to Visual Studio which is essentially a Powershell command prompt. There should be ways of doing most DOS stuff via Powershell and heaps more functionality as well.
Not exactly what you are asking for, but I think you could manage to achieve your goal with StudioShell:
http://studioshell.codeplex.com/
Have to admit that I did not use it so far but it looks very interesting.
Related
I'm trying to run regedit /c reg.txt from within a CygWin bash script to grab the registry contents after which I'll process them with the remainder of the script (yes, I know Powershell is one option but I'd rather stick with the tools I know).
However, when doing this, the regedit program pops up a dialog box complaining about trying to read c:\ and I think this is because CygWin magically converts the /c into the actual drive c:\, similar to the way that cat /h/xyzzy/plugh.txt will show me the file h:\xyzzy\plugh.txt. The dialog box is as follows, you can see the errant parameter underlined:
Is there a way I can stop this translation from happening so that regedit gets the parameters as intended? I've thought of running the regedit separately in a .cmd file but it's a real pain having to maintain two separate files to do a single job (a).
I've also tried running it with cmd /c but that appears to suffer from a similar problem - it just opens up a new command interpreter and waits for input, presumably because the /c is being translated to c:\. While cmd /k dir will list the directory and remain, cmd /c dir does nothing in the cmd.exe instance.
(a) It will work if I use cmd /k otherscript.cmd and then explicitly exit at the end of that script. However, as I said, it's a bit kludgy and I'm pretty certain it would break the second I mount a network share on the k: drive and CygWin starts translating /k into k:\ :-)
As per this MSYS page (upon which MinGW is based, upon which your Git for Windows is based), MSYS will automagically convert POSIX paths to Windows paths for executables not linked to the MSYS DLL.
This includes translating /c into c:\, which is what you're seeing. This explains why both regedit /c reg.txt and cmd /c dir aren't working since the former is attempting to use c:\ as an input to regedit (prompting the warning you see) and the latter is simply starting cmd without executing the arguments.
The method used to prevent translation is to double up the slash, with something like:
regedit //c reg.txt
cmd //c dir
MSYS will remove the leading / and refuse to translate the remainder of the argument, so you'll end up with the /c argument.
You'll still have issues with the first command above since the correct command-line switch to export the registry is /e rather than /c. Change that (and use //e from within MinGW, of course) and it will do what you want.
The question line is actually pretty descriptive. So I'll just be brief here.
I want to use cmd to produce a fresh cmd window that has the #echo off and cls commands already run in it. How can I accomplish this?
My thinking is not constrained to particular method either, I'm interested to see solutions I wouldn't have thought to think of.
To turn echo off and run some commands the easiest is to specify another batch file to run. You can also specify multiple commands inline (Second example)
cmd.exe /q /k yourinitialization.bat
cmd.exe /q /k "dir & cls"
I want to execute three bat files in my script, the problem is when i run these .bat files directly using execwait, command windows gets open, I want to hide these command windows but its not working. My code is of just 3 lines.
ExecDos::exec '"catalina_start.bat"'
ExecDos::exec '"mysql_start.bat"'
ExecDos::exec '"apache_start.bat"'
I also tried this nsExec command but still no solution:
nsExec::Exec "cmd /C catalina_start.bat"
nsExec::Exec "cmd /C mysql_start.bat"
nsExec::Exec "cmd /C apache_start.bat"
A little background on these .bat files, Actually these are files of xampp setup, xampp internally uses these files to start tomcat, mysql, and apache.
The problem I am facing is that only first bat file gets executed, i. e. tomcat gets started (I can see that in xampp console), but then script dosen't move ahead, sql and apache is not getting started.
Does the batch-file contain pause or something else that prevents it from completing?
You should start off just by using something like ExecWait '"cmd.exe" /k "$InstDir\catalina_start.bat"' (or /c) so you can see the text written to the console including any errors. Once it works correctly you can switch to one of the exec plugins that hides the console...
You can change command windows from cmd /C catalina_start.bat to start /Min cmd /c catalina_start.bat it will hide command windows
EDIT
If you want to perform any task at computer startup or based on an
event this is very helpful
http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/how-to-schedule-computer-to-shut-down-at-a-certain/800ed207-f630-480d-8c92-dff2313c193b
Back to the question
I have two questions:
I want some specific commands to be executed when I start command prompt.
e.g. cls to clear my command prompt.
I want to execute some commands in a batch file and wait for the user to enter new commands (if any).
e.g. A batch file which will take the user to some specified folder and then wait for the user to rename/delete a file from the command prompt.
How can I do it?
If you want a defined set of commands to run every time you start a command prompt, the best way to achieve that would be to specify an init script in the AutoRun registry value. Create it like this (an expandable string value allows you to use environment variables like %USERPROFILE%):
reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun ^
/t REG_EXPAND_SZ /d "%"USERPROFILE"%\init.cmd" /f
Then create a file init.cmd in your profile folder:
#echo off
command_A
command_B
...
cls
To remove these changes, delete the registry key:
reg delete "HKCU\Software\Microsoft\Command Processor" /v AutoRun
Make a shortcut
Go to the properties
The bit where it says: C:\Users\<Your username>\Desktop\cmd.exe, you put: -cmd /K <your command here>
e.g.
C:\Users\Lewis\Desktop\cmd.exe -cmd /K color 1f
This is the way to launch 1 command without having to mess about with the registry.
Run multiple commands
You can also use & (and) operator to execute multiple commands.
Eg.
C:\Users\Lewis\Desktop\cmd.exe -cmd /K color 1f & H: & <your command>
Credits: user6589073
I found my answer: I should use the /K switch, using which I can enter a new command on the opened command prompt.
E.g. cmd /K cls will open a command prompt for me and clear it. (Answer for question 1)
and
cmd /K MyBatchFile.bat will start a command prompt, execute the batch file and stay on the command prompt and will not exit. (Answer for question 2).
First, you need to press Windows Key + R.
In the box that appears, type "regedit" (without the quotes).
The Windows Registry Editor should open.
Now, locate to HKEY_CURRENT_USER/Software/Microsoft/Command Processor.
Once you have clicked on Command Processor on the left side, click Edit on the top bar.
Then go to New > String Value in the Edit menu.
Rename the String Value that appears to Autorun.
Right click on Autorun and select Modify.
Under the "Value Data" area, type in the commands you want to run. You can run multiple by typing && between them.
Expanding a bit, here is an alternative for Windows 10 where multiple aliases can be defined and applied to the Command Prompt upon execution.
Create a file called init.cmd containing aliases on your %USERPROFILE% folder:
init.cmd
#echo off
doskey c=cls
doskey d=cd %USERPROFILE%\Desktop
doskey e=explorer $*
doskey g=git status
doskey l=dir /a $*
Register it to be applied whenever the Command Prompt is executed:
In the Command Prompt, run:
reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_EXPAND_SZ /d "%"USERPROFILE"%\init.cmd" /f
Done
Now the contents of init.cmd will run for executions of cmd.exe namely from:
Taskbar shortcut
WIN+R cmd
By typing cmd in the File Explorer address bar
By running cmd.exe directly from C:\Windows\System32
After registering these settings just remember to close/open:
The Command Prompt so the settings are applied
The File Explorer, if you use to launch the cmd via File Explorer address bar
To unregister it, run:
reg delete "HKCU\Software\Microsoft\Command Processor" /v AutoRun
I have a command to run a python program. I do not want to run this command manually after login, I want this command should run automatically after I logged in to my ubuntu. I am using Ubuntu 16.04.
Here is the command.
sh demo_darknet_yolov3.sh , this shell is placed in this directory littro#littro-System-Product-Name:~/MobileNet-YOLO-master/MobileNet-YOLO-master
Depending on your script, you may want to use the cmd.exe /k <input script> method instead of the registry entry Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\autorun
I have found with the latter, that other programs that launch cmd are affected by the registry entry. For example, I cannot get Visual Studio Native Tools prompt to work properly because my script gets in the way. In my case, the script is a menu with 5 options including to launch various programs manually (I like to minimize my auto-run programs) and set various environment variables (ie., printers, proxy settings, default versions of programs, etc).
If you are doing something static I think either method works fine.
I would have commented on the question or an applicable answer, but I do not have the reputation to comment.
anybody know how to minimize the command prompt when running a batch script in Windows 3.11?
in Windows XP, there have a command
start /min start.bat
to minimize the cmd prompt, is it have similiar command in MSDos 6.22?
This little batch code should do what you need.
http://zoombody.com/articles/run-a-batch-script-minimized
The relevant code then needs to be placed at the top of your script:
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
rem Anything after here will run in a minimized window
Here is more information about "%~dpnx0".
There isn't a command that you can use from a DOS prompt, however you can create a PIF file that points to your batch file, in which you can set the default window position (including minimized).
...I think. It's been a couple of decades.
How to minimize the current command prompt:
Purpose:
Close a command prompt after execution.
Open a new command prompt using the same path.
First open command prompt :
Hold down the [Windows] + [R] keys.
Go to this location:
C:\>cd Users\Admin\Desktop
Next excute:
C:\Users\Admin\Desktop>start /min && exit
Results:
A new minimized command prompt should open with the same path.
Alternatively:
Create a script named minimize.bat and type start /min && exit into the script and place it in your system32 folder. In order to have the ability to access it via the command prompt.
Windows 10 makes it very easy to start minimized. Simply create a shortcut and click properties. On the shortcut tab half way down is the "Run:" option witch lets you select how you want the command line window to start up. Just select minimized and your command window will remain minimized from the onset.
Windows10 properties window of a shortcut
Use WinExec to start your batch file and pass SW_SHOWMINIMIZED for the second parameter.
See also, How do I run a batch file with WinExec?