![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Shell.Run problem The two lines of code below, will open a console window, run the dir command and then close the window before the contents can be read. Is there any way to keep the window open and displaying it's contents? The code: Set aShell = Wscript.CreateObject("Wscript.Shell") iret = aShell.Run( "dir", 1, TRUE) -- Peter Gordon |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Shell.Run problem "Peter Gordon" <petergo@xxxxxx> wrote in message news:Xns9BA3574629C80petergonetspacenetau@xxxxxx Quote: > The two lines of code below, will open a console window, > run the dir command and then close the window before > the contents can be read. Is there any way to keep the > window open and displaying it's [its] contents? > > The code: > Set aShell = Wscript.CreateObject("Wscript.Shell") > iret = aShell.Run( "dir", 1, TRUE) > > > -- > Peter Gordon called "dir.exe" or "dir.com". "Dir" is an internal Command Processor command, which means that you must launch cmd.exe to run it, as for some other commands such as cd, md, del, copy. Try this code: Set oShell = WScript.CreateObject("Wscript.Shell") iret = oShell.run("cmd.exe /c dir c:\ & pause", 1, True) To prevent the Console process from closing, add the "pause" command. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Shell.Run problem Hi Peter, better try this one :-) -- Set aShell = Wscript.CreateObject("Wscript.Shell") iret = aShell.Run("cmd /K CD C:\ & Dir") MsgBox iret -- Dirk "Peter Gordon" <petergo@xxxxxx> schrieb im Newsbeitrag news:Xns9BA3574629C80petergonetspacenetau@xxxxxx Quote: > The two lines of code below, will open a console window, > run the dir command and then close the window before > the contents can be read. Is there any way to keep the > window open and displaying it's contents? > > The code: > Set aShell = Wscript.CreateObject("Wscript.Shell") > iret = aShell.Run( "dir", 1, TRUE) > > > -- > Peter Gordon |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Shell.Run problem "Pegasus \(MVP\)" <I.can@xxxxxx> wrote in news:OLHFYSmgJHA.3708@xxxxxx: Quote: > > "Peter Gordon" <petergo@xxxxxx> wrote in message > news:Xns9BA3574629C80petergonetspacenetau@xxxxxx Quote: >> The two lines of code below, will open a console window, >> run the dir command and then close the window before >> the contents can be read. Is there any way to keep the >> window open and displaying it's [its] contents? >> >> The code: >> Set aShell = Wscript.CreateObject("Wscript.Shell") >> iret = aShell.Run( "dir", 1, TRUE) >> >> >> -- >> Peter Gordon > Unfortunately your code won't run anything because there is no > executable called "dir.exe" or "dir.com". "Dir" is an internal Command > Processor command, which means that you must launch cmd.exe to run it, > as for some other commands such as cd, md, del, copy. Try this code: > > Set oShell = WScript.CreateObject("Wscript.Shell") > iret = oShell.run("cmd.exe /c dir c:\ & pause", 1, True) > > To prevent the Console process from closing, add the "pause" command. > > > I've trying to write a script for backing folders on my computer using xxcopy A typical command is: C:\Windows\System32\xxcopy.exe D:\Notes F:\D_Drive\Notes /BI /Y /KS /E /R /Q This backs up D:\Notes to F:\D_Drive\Notes using the options I require. Using an input box, I select the folder to be backed up and the script then runs the appropriate command. It works fine, except for the fact that the cmd window closes before I can read the output from xxcopy. If I open a cmd.exe shell as you have suggested, I cannot input my command into that shell. At the moment, I have a .cmd file of the commands and a pause command in the .cmd file. I then use vbscript to execute the .cmd file. This works fine & the window remains open until I press a key so I can read the xxcopy output. Okay, it works but it is ugly. Is there a more elegant method? Sorry, if I have now over complicated the question. -- Peter Gordon |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Shell.Run problem "Peter Gordon" <petergo@xxxxxx> wrote in message news:Xns9BA3574629C80petergonetspacenetau@xxxxxx Quote: > The two lines of code below, will open a console window, > run the dir command and then close the window before > the contents can be read. Is there any way to keep the > window open and displaying it's contents? > > The code: > Set aShell = Wscript.CreateObject("Wscript.Shell") > iret = aShell.Run( "dir", 1, TRUE) > > > -- > Peter Gordon iret = aShell.Run("%comspec% /k dir c:\", 1, True) or iret = aShell.Run("%comspec% /c dir c:\ & pause", 1, True) The %comspec% environment variable refers to the correct command depending on the operating system. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Shell.Run problem "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in news:ennnjGngJHA.4556@xxxxxx: Quote: > > "Peter Gordon" <petergo@xxxxxx> wrote in message > news:Xns9BA3574629C80petergonetspacenetau@xxxxxx Quote: >> The two lines of code below, will open a console window, >> run the dir command and then close the window before >> the contents can be read. Is there any way to keep the >> window open and displaying it's contents? >> >> The code: >> Set aShell = Wscript.CreateObject("Wscript.Shell") >> iret = aShell.Run( "dir", 1, TRUE) >> >> >> -- >> Peter Gordon > Best is actually: > > iret = aShell.Run("%comspec% /k dir c:\", 1, True) > > or > > iret = aShell.Run("%comspec% /c dir c:\ & pause", 1, True) > > The %comspec% environment variable refers to the correct command > depending on the operating system. > ret = xxcopyShell.Run( "xxcopy D:\Notes F:\Notes /BI", 1, TRUE) and make the shell pause, (i.e remain open) after the command is executed? -- Peter Gordon |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Shell.Run problem "Peter Gordon" <petergo@xxxxxx> wrote in message news:Xns9BA374154A9B6petergonetspacenetau@xxxxxx Quote: > "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in > news:ennnjGngJHA.4556@xxxxxx: > Quote: >> >> "Peter Gordon" <petergo@xxxxxx> wrote in message >> news:Xns9BA3574629C80petergonetspacenetau@xxxxxx Quote: >>> The two lines of code below, will open a console window, >>> run the dir command and then close the window before >>> the contents can be read. Is there any way to keep the >>> window open and displaying it's contents? >>> >>> The code: >>> Set aShell = Wscript.CreateObject("Wscript.Shell") >>> iret = aShell.Run( "dir", 1, TRUE) >>> >>> >>> -- >>> Peter Gordon >> Best is actually: >> >> iret = aShell.Run("%comspec% /k dir c:\", 1, True) >> >> or >> >> iret = aShell.Run("%comspec% /c dir c:\ & pause", 1, True) >> >> The %comspec% environment variable refers to the correct command >> depending on the operating system. >> > How do I run: > ret = xxcopyShell.Run( "xxcopy D:\Notes F:\Notes /BI", 1, TRUE) > and make the shell pause, (i.e remain open) after the command is > executed? > > > -- > Peter Gordon ======== Set aShell = Wscript.CreateObject("Wscript.Shell") strCmd = "%comspec% /k xcopy ""D:\Notes"" ""F:\Notes"" /BI" Wscript.Echo strCmd ret = aShell.Run(strCmd, 1, True) ======== I assume you meant the xcopy command. Note that I enclosed the paths in quotes in case there are any spaces. In a quoted string (like the value of the strCmd variable) any embedded double quotes must be doubled. I echo the command line to the console so I can see what it looks like and verify that it is correct. The /k parameter keeps the command shell open until you exit. Finally, it might make sense to use RoboCopy instead. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Shell.Run problem "Pegasus (MVP)" <I.can@xxxxxx> wrote in message news:OLHFYSmgJHA.3708@xxxxxx Quote: > > "Peter Gordon" <petergo@xxxxxx> wrote in message > news:Xns9BA3574629C80petergonetspacenetau@xxxxxx Quote: >> The two lines of code below, will open a console window, >> run the dir command and then close the window before >> the contents can be read. Is there any way to keep the >> window open and displaying it's [its] contents? >> >> The code: >> Set aShell = Wscript.CreateObject("Wscript.Shell") >> iret = aShell.Run( "dir", 1, TRUE) >> >> >> -- >> Peter Gordon > Unfortunately your code won't run anything because there is no executable > called "dir.exe" or "dir.com". "Dir" is an internal Command Processor > command, which means that you must launch cmd.exe to run it, as for some > other commands such as cd, md, del, copy. Quote: > Try this code: > > Set oShell = WScript.CreateObject("Wscript.Shell") > iret = oShell.run("cmd.exe /c dir c:\ & pause", 1, True) > > To prevent the Console process from closing, add the "pause" command. Set oShell = WScript.CreateObject("Wscript.Shell") iret = oShell.run("cmd.exe /k dir c:\", 1, True) this will keep the command window open and usable, allowing the user to examine environment variables or what have you before closing the window with exit. /Al |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Shell.Run problem "Al Dunbar" <alandrub@xxxxxx> wrote in news:e2S2u60hJHA.4596@xxxxxx: Quote: > > "Pegasus (MVP)" <I.can@xxxxxx> wrote in message > news:OLHFYSmgJHA.3708@xxxxxx Quote: >> >> "Peter Gordon" <petergo@xxxxxx> wrote in message >> news:Xns9BA3574629C80petergonetspacenetau@xxxxxx Quote: >>> The two lines of code below, will open a console window, >>> run the dir command and then close the window before >>> the contents can be read. Is there any way to keep the >>> window open and displaying it's [its] contents? >>> >>> The code: >>> Set aShell = Wscript.CreateObject("Wscript.Shell") >>> iret = aShell.Run( "dir", 1, TRUE) >>> >>> >>> -- >>> Peter Gordon >> Unfortunately your code won't run anything because there is no >> executable called "dir.exe" or "dir.com". "Dir" is an internal >> Command Processor command, which means that you must launch cmd.exe >> to run it, as for some other commands such as cd, md, del, copy. > Unless, of course, there is a dir.bat or dir.cmd file... > Quote: >> Try this code: >> >> Set oShell = WScript.CreateObject("Wscript.Shell") >> iret = oShell.run("cmd.exe /c dir c:\ & pause", 1, True) >> >> To prevent the Console process from closing, add the "pause" command. > Another method would be this: > > Set oShell = WScript.CreateObject("Wscript.Shell") > iret = oShell.run("cmd.exe /k dir c:\", 1, True) > > this will keep the command window open and usable, allowing the user > to examine environment variables or what have you before closing the > window with exit. > > /Al which works well. Set xxcopyShell = Wscript.CreateObject("Wscript.Shell") strXXCOPY = "%comspec% /c xxcopy.exe " strOptions = " /BI /Y /KS /E /R /X*\Tmp\ /Q " strCmd = strXXCOPY & strOptions & strFiles & " & pause" ' MsgBox strCmd, vbOkOnly, "The Command" ret = xxcopyShell.Run( strCmd, 1, TRUE) -- Peter Gordon |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Shell.Run problem hi all my problem is like this subject. when you run your script from 25*80 (full screen mode) command prompt, & your script call a win app (such as notepad) you can't go back to command prompt automaticly & need to push "enter" key for this. why or how to do it? *** Sent via Developersdex http://www.developersdex.com *** |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Can parent shell monitor run/crash status of Child shell/exe ? | PowerShell | |||
| Problem with WSH Shell Exec StdOut | VB Script | |||
| problem with shell.application | PowerShell | |||
| Executing Power Shell Scripts from Windows Shell | PowerShell | |||