Jump to content

_RunDos() doesn't work but DOS commands work!


Recommended Posts

Hi everibody!

Under WinXP SP2: DOS comands work normally in a DOS window but not as argument of _RunDos() function.

I mention that those commands as argument of _RunDos() function work fine on any other PCs so the syntax of _RunDos() is correct. The same result under 3 different Autoit versions.

If there is somebody who has had such a problem or he could preview its solution, please answer here.

Thanks in advance!

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

_RunDOS is the same as:

Run(@ComSpec & " /c " & 'command', "", @SW_HIDE)

Could you try:

$iResult = Run(@ComSpec & " /k " & 'command', "", @SW_HIDE)
MsgBox(0, "", "$iResult = " & $iResult & ", @error = " & @error)

BTW: Which version of AutoIt do you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank you @water

$iResult = 0, @error = 1
View/Output: Exit code: 0   Time: ...

The strange part is the missing of error code although there is an error (@error = 1). On the other hand, it is normally
because on any other PC the function _RunDos works great. I suspect some corrupt files on HDD so I will give it a chkdsk command and I'll
be back with the result.

Versions: 3.3.0.0 and then 3.3.8.1 and the same results.

Edited by silpower
Link to comment
Share on other sites

$iResult should be the PID (process ID) of the started process. 0 means: No process started. Most of the time this means that the program you try to start could not be found.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Can you please post the full line of your script that doesn't work?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Doesn't matter the script. Any simple command doesn't work: net send, start program, etc, for example. In command window all is OK but in AutoIT under '_RunDos' doesn't. No matter the script, on other PCs works great.

The function 'Run' in AutoIT works great. Only '_RunDos' has the problem. Maybe some part in WindowsXP interacts badly with the action of  '_RunDos' function or a setting in XP that prohibits the proper functioning of this function.

I have to study the action of @ComSpec. In Help files it says:

value of %comspec%, the SPECified secondary COMmand interpreter;
primarly for command line uses, e.g.  Run(@ComSpec & " /k help | more")

Link to comment
Share on other sites

The same ... View/Output: Exit code: 0   Time: ...

Of course on other PC - no problem.

Anyway thanks for suggestion, PincoPanco. I repeat: everything is OK in command window but not in _RunDOS(). And belive me that I use #include <Process.au3> ... Always the explanation is simple but it become simple after we get it.

Link to comment
Share on other sites

The same ... View/Output: Exit code: 0   Time: ...

Of course on other PC - no problem.

Anyway thanks for suggestion, PincoPanco. I repeat: everything is OK in command window but not in _RunDOS(). And belive me that I use #include <Process.au3> ... Always the explanation is simple but it become simple after we get it.

 

excuse me silpower,

I do not understand if the example above ( _GetDOSOutput ) works on the problematic computer or not??

do you see the output of the ping command in the SciTE output console ?

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

What do you mean by "nothing happens"? _RunDOS runs in a hidden console window, so you won't see anything on the screen. If you're wanting to see something from the command, don't use _RunDOS.

 

Func _RunDos($sCommand)

Local $nResult = RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE)

Return SetError(@error, @extended, $nResult)

EndFunc   ;==>_RunDos

 

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

Link to comment
Share on other sites

What do you mean by "nothing happens"? _RunDOS runs in a hidden console window, so you won't see anything on the screen. If you're wanting to see something from the command, don't use _RunDOS.

 

right, ..... but OP say that the same script works on other computers

while it doesn't only on one problematic PC. so it seems that is a PC problem and not a script problem.....strange,

I would like to see the code that OP uses

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

You're right PincoPanco, it is a problem specific to a PC only. The annoying thing is that I can't see the problem with @comspec. I suspect Windows doesn't use command.com when _RunDos wants. AutoIT see that fact and it sets @eror=1 and @Execution_Result = 0 but if we look in the menu View/Output we just see ExitCode =0 and Time = ... as though everithing would be OK. On the other hand this fact is normal because the script doesn't have any bug.

So we can rephrase the question as follows: What settings should be checked in order to ensure that AutoIT sends my DOS command to command.com.

PincoPanco: As I wrote, no matter the script, it is not a scripting problem. Let's get the simplest example - the example from the Help section:

#include <Process.au3>
Local $rc = _RunDos("start iexplore.exe")

On the problematic computer, it doesn't work. That means IE doesn't start. (Obviously on any other PC all is normal). Any other example works in the same way: 'net send' message, compress files with 7za.exe, etc.

And thank you guys for your efforts to think at my problem.

Edited by silpower
Link to comment
Share on other sites

to see what is @comspec on ​​your problematic computer try this:

MsgBox(0, "", "@comspec is : " & @ComSpec)

edit:

after that, open a dos prompt and type ECHO %COMSPEC%

are the two output the same?

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Don't use Start, there's no need to. Second, try with a full path and filename just to be on the safe side. Third, there's a whold UDF dedicated to Internet Explorer that would probably be far better for your needs than the _RunDOS command would.

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

Link to comment
Share on other sites

Don't use Start, there's no need to. Second, try with a full path and filename just to be on the safe side. Third, there's a whold UDF dedicated to Internet Explorer that would probably be far better for your needs than the _RunDOS command would.

@BrewManNH

Bad guess.

The _RunDOS Function's parameter, $sCommand, has to be a DOS recognizable command. "Start" is a DOS command.  'iexplore.exe' by itself is not recognized as an internal or external command, operable program or batch file when used at the cmd.exe command prompt.

This is probably why the _RunDOS function example in the help file uses "Start".

@silpower

Notice the preceeding underscore in the _RunDOS function. This "_", underscore indicates a User Defined Function, (UDF).  From the AutoIt helpfile under the _RunDOS function, the "#include <Process.au3>" tells that the _RunDOS function is stored in the Process.au3 file which is in the AutoIt's include directory.  So when Water in post #2 uses the Run function, you can check to see he should have used the RunWait function for accuracy sake.

Further to your post #7, here is more study material on @ComSpec if you are interested.

MsgBox(0, "", "@ComSpec  = " & @ComSpec & @LF) ; Full path\cmd.exe

; Shows Dos help on the cmd function.  Explains the switches "/C" or "/K".
Run(@ComSpec & " /K cmd /?") ;

Edit: Was a path problem. When "C:\Program Files\Internet Explorer\" added to systems environmental path variable, "iexplore.exe" works fine.

Edited by Malkey
Link to comment
Share on other sites

@BrewManNH

Bad guess.

The _RunDOS Function's parameter, $sCommand, has to be a DOS command. "Start" is a DOS command.  'iexplore.exe' by itself is not recognized as an internal or external command, operable program or batch file when used at the cmd.exe command prompt.

This is probably why the _RunDOS function example in the help file uses "Start".

Really? I'm pretty sure that on every computer I've ever used, iexplore.exe is in "C:\Program Files\Internet Explorer\" and it runs IE when I click on it. If I type the full path and file name in the console it runs IE. If I run it with Start, it opens a NEW window and runs IE. Which is probably why the OP can't get anything back from his _RunDOS command. _RunDOS uses RunWait, as soon as you use Start, RunWait returns with a success, and RunDOS ends, and you get nothing returned from the program you started.

I stand by what I said, while using Start will allow you to start IE that way, you aren't going to get much out of it using it inplace of just using the program you want started.

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

Link to comment
Share on other sites

Sounds to me like a path problem.  Try doing as BrewManNH suggested, and give the full path to the executable, and see what happens.

If that works, then you need to look at your system path variable.  (Right click My computer.  Click on Properties.  Select the Advanced tab.  Click on Environment Variables.  Under System variables, look for Path.)

It should at absolute minimum contain

%SystemRoot%\system32;%SystemRoot%
Link to comment
Share on other sites

The Environment VariablePath and services I already have compared with other computer where all is OK.

It is correct what BrewManNH says but the same result is for any other DOS command: For example using 'net send' command.

Net send 10.x.x.x message. PC belongs to a domain.

For two weeks I will be away from the base for equipments installation. At return I wiil try a WinXP repair and all your suggestion regarding full path and @comspec.

In the meantime, if you have any other suggestions, please put them here. I assure you I shall check all of them and revert back with result.

 
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...