Jump to content

Command line


Recommended Posts

I did not see any example like this one

I type that line at the dos  cmd prompt and it's run I am wondering , how to do the same with autoit

 

$step3Cmd = "d:\ClientAdmin\RetailPatch\retailPatch.bat storeregister r07v06 stop-pos-and-change-N"

 

Edited by antonioj84
error
Link to comment
Share on other sites

9 minutes ago, antonioj84 said:
$run=Run(@Comspec & " /c " & $step3Cmd)
if not processExist($run) then...

Yes,  would that work ?or Processwaitclose($run)

No, the one you posted will not work.  It will simply check to see if the process exists or not immediately after running it (which will mean that whatever you put in the code block will get skipped because the process will exist).  I would go with

$run=Run(@Comspec & " /c " & $step3Cmd)
Processwaitclose ( $run )

This way, the script will not execute any more code until the process that you initially ran is finished.

Link to comment
Share on other sites

19 hours ago, antonioj84 said:

@ whiggs , the reason it's a batch file although it finishes there is still  a DOS windows, which I think may indicate falsely that the process still running

however with the command line or the process UDF  you can have an exit code

 

If anything, you would probably run into an error like that as the batch script is executing (eg if you are performing installs in the batch script and one of the exe's spawn a separate process for the install and the script moves on to the next install, run into that one before), but that would be confined to the batch script itself, and the batch script would still show as "running" until the commands that it is executing were complete.  But its all good dude.  You don't have to justify why you write your code the way you do to me.  We all have our own way of thinking.  Whatever works, right?

Link to comment
Share on other sites

16 minutes ago, antonioj84 said:

@whiggs i appreciate your input, however using the processwaitclose will wait forever or  how would  the script knows this  has been completed      ?

the script below is completed.

dhcp.JPG

 
 
6

Well, since the batch file does not include the line "echo off", I can see that the problem could be resolved by removing the last line if you wanted to (PAUSE).  Perhaps replace PAUSE with "timeout 5", which will countdown from 5 and then continue the script.  Or maybe PAUSE was put in there so that you could take a snapshot, in which case the script will know the batch file has finished by assigning a variable to the process handle when the batch file is run, then making the next function "PRocessWaitclose ( $processhandle).  If you use the RunWait functions provided in earlier posts, the console window will close after the batch file has finished executing (per the " /c" following @Comspec).  This is just a suggestion, but why are you running these commands in an external batch file?  Why not run them in autoit using "Run", "RunWait", "ShellExecute", or "ShellexecuteWait"?  You could then compile the script as a command line utility and it would display the output for these functions just like what is displayed in the picture you posted and you will have a process handle for each individual command rather than a single one for the batch script, which would offer you more control rather than depending on the the script to successfully execute all of the commands.

Edited by whiggs
Link to comment
Share on other sites

I think you are incorrect try this, these batches are legacy and have pause at the end, and are bake into to the images, therefore using  the example below as you suggested will not work, the shellexcutewait  command will wait forever

ShellExecuteWait("dhcpbat.bat","",@ScriptDir,"",@SW_HIDE) or create any bat files with pause at the end

dhcpbat.txt

Edited by antonioj84
error
Link to comment
Share on other sites

31 minutes ago, antonioj84 said:

I think you are incorrect try this, these batches are legacy and have pause at the end, and are bake into to the images, therefore using  the example below as you suggested will not work, the shellexcutewait  command will wait forever

ShellExecuteWait("dhcpbat.bat","",@ScriptDir,"",@SW_HIDE) or create any bat files with pause at the end

dhcpbat.txt

 
 

Ok, so let me make sure I understand this correctly.  Are you saying that batch files automatically incorporate a "PAUSE" at the end of the file?  I am looking at the text file you sent me, and I can see the Pause included at the end.  That is what is causing the script to wait forever.  If you get rid of the "PAUSE", it will run to completion.  Just to make sure, I did a little test: I created a batch script with the following contents:

echo off

timeout 4

Then I created an autoit script with the following:

RunWait ( @DesktopDir & "\b.bat" )
MsgBox ( 1, "", "It is done" )

Where b.bat is the batch file that I created in the previous step.  When executed, the script will run the batch file and, when the script detects that it is finished executing, will display a message box.  Worked exactly as I thought it would/described: after the batch file waited for 4 seconds, the batch file process ended and the autoit script displayed the message box.  I'm not sure what you are talking about in terms of the PAUSE being built into the script.  They are not, you just need to remove the "Pause" line in the txt file you sent.  If you need the script to pause for a period of time to see results, I would recommend replacing PAUSE with "timeout n", where n is an integer representing the number of seconds you want the batch script to pause its execution.

Edited by whiggs
Link to comment
Share on other sites

says whiggs "  Are you saying that batch files automatically incorporate a "PAUSE" at the end of the file?  " yes you are correct they are legacy batch files bake into the images and the batch files reside in 5000 computer, removing the "pause" is not an option, the idea is to work around.

Link to comment
Share on other sites

Ah, I see.  I am guessing that this is some kind of deployment that you are doing.  In that case, if the batch files are already on the computers, why not just have the script re-write the batch file/create a new batch file without the pause:

#include <Array.au3>
#include <File.au3>
;FileCopy ( "C:\path\to\batch\file\on\deployed\computers\oldscript.bat", "C:\path\to\batch\file\on\deployed\computers\newscript.bat" )
$filelines = FileReadToArray ( "C:\path\to\batch\file\on\deployed\computers\oldscript.bat" )
$remove = 0
For $i = 0 To UBound ( $filelines ) - 1 Step 1
    If StringLeft ( $filelines[$i], 5 ) = "netsh" Then
        $filelines[$i] = $filelines[$i] & ' > "C:\output\for\the\netsh\command\output1.txt"';modifies the batch file lines containing the commands which contain information to output that information to a txt file on the local machine.
    EndIf
    If $filelines[$i] = "PAUSE" Then
        $remove = $i
    EndIf
Next

_ArrayDelete ( $filelines, $remove )
$file = FileOpen ( "C:\path\to\batch\file\on\deployed\computers\newscript.bat", $FO_OVERWRITE )
_FileWriteFromArray ( $file, $filelines )
FileClose ( $file )
RunWait ( "C:\path\to\batch\file\on\deployed\computers\newscript.bat" )

#cs
Code to gather the information which the new batch file outputs to the txt files can be put here.
See, there are a million and one ways to skin a cat.
#ce

Again, these are just solutions.  If you already have your solution and it works for you, all power to you.  This is just a potential solution.

Edited by whiggs
Link to comment
Share on other sites

5 minutes ago, antonioj84 said:

great you understand the issue, thank you for the snippet, and your suggestion,  this is one  option worth looking into, not sure if they will approve it.

 

 

Isn't corporate red tape just the worst...:ranting::ranting:  Fingers crossed.  And the portion that comes after the script is run that collects the information from the text files, you can always read the contents of the files into an array (like i did with "oldscript", output the information in your autoit script, and then delete the output files..  Hopefully it works out for you.

Link to comment
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
 Share

×
×
  • Create New...