Sign in to follow this  
Followers 0
breslosm

Issue with For loop and/or CMD.exe

7 posts in this topic

Whenever I run the following code, the loop never makes it all the way to $end ($start = 30628752, $end = 30629085).  Any ideas as to why this could be happening?

Global $start = InputBox("Start", "Enter Start Cluster")
Global $end = InputBox("End", "Enter End Cluster")
Run("cmd.exe")
WinWaitActive("Administrator: C:\Windows\system32\cmd.exe")
Send("cd tsk{ENTER}cd bin{ENTER}")
For $i = $start to $end Step 1
     Send("blkstat \\.\C: "&String($i)&" >> "&$path&"\CLUSTER"&String($i)&".txt{ENTER}")
     ProcessWait("blkstat.exe")
Next

 Thanks

Share this post


Link to post
Share on other sites



How far does it get, and why are you using the command prompt and Send to run a program?


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

Thanks for the prompt response.

It gets to a different number every time (I call it several times during the course of a larger script, without ever changing $start or $end) but usually at least until 30628799.  I am using the command prompt and Send because I need to call blkstat.exe with parameters and redirect the output to a file.  If you know of anoter way of doing that I'd certaibly be willing to give it a try.

Share this post


Link to post
Share on other sites

Look in the help file for Run and/or ShellExecute, both would be far more reliable than using send on the command prompt.


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 had considered that but the problem with Run/ShellExecute is that Run can't pass parameters and ShellExectue can't redirect output (because it does not return a process ID which is required to read from stdout).  Any other ideas?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Who says Run can't pass parameters? This is the same command as the Send command using Run instead, although I'd specify the full path to the blkstat program in the Run command to be 100% sure you're going to be able to find it.

Run("blkstat \\.\C: " & String($i) & " >> " & $path & "\CLUSTER" & String($i) & ".txt")
Edited by BrewManNH

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

Ah I hadn't realized that was how Run worked (for whatever reason I thought it could only take an executable as a parameter, not the whole line as you've described above).  I'll give it a shot and see it it runs all the way through the loop now.  Thanks again.

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