Sign in to follow this  
Followers 0
Zohar

[Closed] Running a DOS Command with /C and /K

10 posts in this topic

#1 ·  Posted (edited)

Hi


I have a DOS program that I need to run, and I want to prevent the DOS window from closing quickly after the program finished,
so for this I am going to use the /K option.

I just have a problem in understanding some remark, that appears when running "cmd/?":

Please have a look at the part inside the rectangle:
http://imgur.com/eJ7cEkP
(BTW, how do I add an Image here in the new forum system??? There is no "Add Image" button on the toolbar... :| )


I especially don't undetrstand #2 there..

BTW, The reason I need to understand this part, is because I am going to have several double quotes in the command (for specifying files full path, that includes spaces in the filename or folder name)


Thank you to anyone who can help..

Edited by Zohar

Share this post


Link to post
Share on other sites



Can you show an example of the command line that you need, with the correct quotes in it?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

An example, for this specific thing that I am doing, is this:
PROGRAM.EXE "C:\Program Files\file name1.ext" "C:\Program Files\file name2.ext"
(this is what will come after the /K part)


But on another occasion I might need something else of course,
so understanding it is critical..

Edited by Zohar

Share this post


Link to post
Share on other sites

Something like this should work, surround the run command line with single quotes.

Run(@ComSpec & ' /k PROGRAM.EXE "C:\Program Files\file name1.ext" "C:\Program Files\file name2.ext"' )

A quick troubleshooting tip, Change the Run to Consolewrite and tack on @CRLF before the final parentheses (or after the final single quote) to see what the command looks like when you run it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

What you describe is how to work with AutoIt's Quotes/DoubleQuotes - something which I know..
What I brought in the screenshot, talks about what cmd.exe does with the quotes you give it after the "cmd.exe /K" part, and that's what I'm trying to understand.

Also,
I am interested in understanding the remark there not just for this one specific program that I work on now,
but in general..

So anyone who understood it, please write.

Thanks

Share this post


Link to post
Share on other sites

This site deals with AutoIt, you might get better answers in regards to Windows cryptic explanations on a Windows site.

Regardless, how about just trying it and seeing what comes out with various quoting instead of asking what it will do? It would probably take you far less time to actually try something before trying to find out if anyone else has done it before you. This way you'll learn something new.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I actually tried, and I already finished what I was about to do..
But as I wrote, the purpose is to understand the remark there in general, for all projects, not just one.

Also not completely understanding the remark, might come back to a person later, when unexpected..
So while I am "done" with what I wanted to create, it's not done till all the little risk are completely removed..

You are right regarding trying in another forum.
If there will be no answer here, I will try again in a Windows forum..

Share this post


Link to post
Share on other sites

You know, that makes some sense now concerning a situation I was running into trying to install a service into Windows 7. Using this method:
https://support.microsoft.com/en-us/kb/137890

Since both binaries were in Program Files (x86) I had to add quotes. No combination of single/double quotes or Chr(34) in AutoIT was letting me properly pass the command. Either it was removing a double quote or not understanding the single quotes.

However, if you note that KB says that is for Windows NT, I found a way around by using the sc.exe that is built into the OS.
Code examples, non-working (maybe) remarked.

; create service1 with instsrv (deprecated)
; RunWait (@ComSpec & " /c " & Chr(34) & "c:\Program Files (x86)\Service\instsrv.exe" & Chr(34) & " Service1 " & Chr(34) & "C:\Program Files (x86)\Service\srvany.exe" & Chr(34) )
; create service1 with sc
RunWait (@ComSpec & " /c sc create Service1 binpath= " & Chr(34) & "c:\program files (x86)\Service\srvany.exe" & Chr(34) & " start= auto" )

The instsrv.exe required full paths on both, which required encapsulating each due to the space in the dir name. Using environment or autoit variables did not help. Perhaps it is a separate issue, but makes me think it is related.

Share this post


Link to post
Share on other sites

Yeah indeed.
I did not manage to wrap the executable with "",
only parameters that come after it.

That means that the executable's full path, has to be one that does not include a space in it..
Or, to use the second parameter (Working Dir) for the path, and the filename will remain in the first parameter(but again, the filename itself will not be able to include a space..)

Or..
If we solved the remark specified in cmd.exe, which is completely not phrased well :)

Share this post


Link to post
Share on other sites

Try it with ShellExecute instead and see if that works. Also, try running it without @ComSpec and see if that works as well. The window will close at the end of the run, but at least it is something you can try and see if it works.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0