Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing values to a command prompt 3

Status
Not open for further replies.

AgentM

MIS
Jun 6, 2001
387
US
When you run the command "del C:\SomeFolder" it asks for "do u really want to delete?".

Now that second prompt can be excluded if I used the "/q" switch.

But there are some commands that do not have the "/q" switch, is there any way I can pass the "Y" to the prompt?

any help appreciated.

 
AgentM,
are you using vbscript or dos commands?
you can delete folders / files with the filesystemobject and it does not prompt you.
if you could give a little more info as to what commands you are looking to run it would be helpful.
regards,
longhair
 
I can use VBScript or DOS or Both.
I am trying to automate the command "convert /C: /FS:NTFS"

 
Thanks earthandfire.
I am using echo Y | convert C: /FS:NTFS

Can you explain "NUL"?
Thanks.


 
AgentM,
the '>' is passing the info / response from the convert command into nul - that is nothing.
if you did > temp.txt it would pass the info into a .txt file named temp.
regards,
longhair
 
I need to do a restart too after this command is run, Can I do that too in the same command? using shutdown -r -t 1

Thank you
 
Code:
DOS Device names

Name            Device
AUX             Default for COM1
PRN             Default for LPT1
COM1 to COM4    Serial ports
LPT1 to LPT3    Parallel ports (printer)
CON             Keyboard (input) and screen (output)
NUL             Nothing (also known as a "bit bucket")

also

Default DOS File Handles - these are (nearly) always available

Name            Name, Device(Handle)           
STDIN, STDOUT   CON, Keyboard (0), Screen (1)
STDERR          , Error (2)                      
STDAUX          AUX, COM1 (3)                  
STDPRN          PRN, LPT1 (4)


Basically output generally goes to the screen. When you redirect it you need to specify a target this can either be a file or one of the predefined names. NUL means nothing (or in this context nowhere), so output will just be thrown away by DOS.


Hope this helps .

[vampire][bat]
 
You wanted this ?
yourObj.Run "CMD /C echo Y | convert C: /FS:NTFS & shutdown -r -t 1"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yes, but here's a slight issue.
I only want to do a shutdown if convert c: /FS:NTFS returns a particular set of strings.
E.g. sometime if the drive is already NTFS then the convert will just say "drive is NTFS" and exit gracefully.
Then I do not want to do a shutdown.

How can I incorporate that "if" condition?
 
Convert.exe Exits with ErrorLevel 4 when it "fails"

Drive C: is already NTFS.
ERRORLEVEL 4

Invalid drive specification.
ERRORLEVEL 4

Must specify a file system
ERRORLEVEL 4

Based on that you should be able to test for the errorlevel and bypass the reboot.

Code:
Dim ErrorLevel 
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell") 
ErrorLevel = objShell.Run ("convert c: /FS:NTFS",2,True) 

If ErrorLevel = 4 Then 
r = objShell.Popup("Already NTFS", 4, "Convert",48)
Else
r = objShell.Popup("Converting Drive to NTFS", 4, "Convert",5)
objShell.Exec("shutdown -r -t 1")
End If 
'WScript.Echo ErrorLevel

Darn it took awhile to find how to get the errorlevel from the DOS window, but I figured it out.

This little bit of DOS code is very handy too.

Code:
REM Check error level tenfolds
FOR %%A IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL %ERR100%%%A0 SET ERR10=%%A
IF "%ERR100%"=="" IF %ERR10%==0 SET ERR10=

:1
REM Check error level units
FOR %%A IN (0 1 2 3 4 5) DO IF ERRORLEVEL %ERR100%%ERR10%%%A SET ERR1=%%A
REM Modification necessary for errorlevels 250+
IF NOT ERRORLEVEL 250 FOR %%A IN (6 7 8 9) DO IF ERRORLEVEL %ERR100%%ERR10%%%A SET ERR1=%%A
GOTO End

:200
REM In case of error levels over 200 both
REM tenfolds and units are limited to 5
REM since the highest DOS error level is 255
FOR %%A IN (0 1 2 3 4 5) DO IF ERRORLEVEL 2%%A0 SET ERR10=%%A
IF ERR10==5 FOR %%A IN (0 1 2 3 4 5) DO IF ERRORLEVEL 25%%A SET ERR1=%%A
IF NOT ERR10==5 GOTO 1

:End
REM Clean up the mess and show results
SET ERRORLEV=%ERR100%%ERR10%%ERR1%
FOR %%A IN (1 10 100) DO SET ERR%%A=
ECHO ERRORLEVEL  %ERRORLEV%

Thanks

John Fuhrman
Titan Global Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top