Sign in to follow this  
Followers 0
autoitquestion

Answer of _RunDOS

11 posts in this topic

Hi,

When I do:

$output=_RunDOS('tasklist /FI \"IMAGENAME eq Noa.exe\"') and process exist so it return $output=0 and also if process not exist is return the same

why it's did not return me the answer of dos, so I'll test if process exist or not according the answer of dos

hope my question is clear

Thx,

Noa :-)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

_RunDos :

Success: Returns the exit code of the command

Failure: Returns 0 and sets @error to non-zero.

What you want is something like that :

#include <Constants.au3>

$_Run = @ComSpec & ' /c tasklist /FI \"IMAGENAME eq Noa.exe\"'
ConsoleWrite ( ' $_Run : ' & $_Run & @Crlf )
$_Pid = Run ( $_Run, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD )
Dim $_StderrRead='', $_StdoutRead=''

While ProcessExists ( $_Pid )
    $_StderrRead = StderrRead ( $_Pid )
    If Not @error And $_StderrRead <> '' Then ConsoleWrite ( "STDERR read : " & $_StderrRead & @Crlf )
    $_StdoutRead = StdoutRead ( $_Pid )
    If Not @error And $_StdoutRead <> '' Then ConsoleWrite ( "STDOUT read : " & $_StdoutRead & @Crlf )
Wend
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

thanks!

I tried make it short and do:

#include <Constants.au3>

$_Run = @ComSpec & ' /c tasklist /FI "IMAGENAME eq noa.exe"'
ConsoleWrite ( ' $_Run : ' & $_Run & @Crlf )
$_Pid = Run ( $_Run, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD )
Dim $_StderrRead='', $_StdoutRead=''

While ProcessExists ( $_Pid )
    $_StdoutRead = StdoutRead ( $_Pid )
    If Not @error And $_StdoutRead <> '' Then ConsoleWrite ( "STDOUT read : " & $_StdoutRead & @Crlf )
Wend
    
If StringInStr($_StdoutRead,"INFO")=0 Then 
    ConsoleWrite("Process exist")
Else
    ConsoleWrite("Process not exists")
EndIf

However, cmd give me this answer:

STDOUT read : INFO: No tasks are running which match the specified criteria.

And it write:

Process exist

Any advice pls?

Edited by autoitquestion

Share this post


Link to post
Share on other sites

thanks!

I tried make it short and do:

However, cmd give me this answer:

STDOUT read : INFO: No tasks are running which match the specified criteria.

And it write:

Process exist

Any advice pls?

That want to say there is no process named noa.exe ! that's all !

Verify with your TaskManager.


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

How to verify it with Task Manager?

without task manager I did:

#include <Constants.au3>

$_Run = @ComSpec & ' /c tasklist /FI "IMAGENAME eq noa.exe"'
ConsoleWrite ( ' $_Run : ' & $_Run & @Crlf )
$_Pid = Run ( $_Run, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD )
Dim $_StderrRead='', $_StdoutRead=''

While ProcessExists ( $_Pid )
    $_StdoutRead = StdoutRead ( $_Pid )
    If Not @error And $_StdoutRead <> '' Then ConsoleWrite ( "STDOUT read : " & $_StdoutRead & @Crlf )
Wend
ConsoleWrite("output now is:"&$_StdoutRead&@CRLF)
If StringInStr($_StdoutRead,"Image")=0 Then 
    ConsoleWrite("Process not exist")
Else
    ConsoleWrite("Process exists")
EndIf
Edited by autoitquestion

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If you want to know if a process exists Then Use ProcessExists ( 'noa.exe' )

or ProcessList

Edit : for get a clear answer, ask directly what you want do !

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

In fact you want close all "noa.exe" process ?

So try this

$list = ProcessList ( "noa.exe" )
For $i = 1 to $list[0][0]
    ProcessClose ( $list[$i][1] )
Next

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

In fact you want close all "noa.exe" process ?

not exactly-I wish to know if it's exist or not

I do commands respectively in my script

I need also below code:

While ProcessExists ( $_Pid )
    $_StdoutRead = StdoutRead ( $_Pid )
    If Not @error And $_StdoutRead <> '' Then ConsoleWrite ( "STDOUT read : " & $_StdoutRead & @Crlf )
Wend

In order to know what I am getting in stdout

How can I combine your above given code in the current?

Thanks a lot!!!

Noa :-)

Share this post


Link to post
Share on other sites

If you want to know if processexist try like this

$list = ProcessList ( "noa.exe" )
If UBound ( $list ) > 1 Then
    ConsoleWrite ( "Process found !" & @Crlf )
    For $i = 1 to $list[0][0]
        ProcessClose ( $list[$i][1] )
    Next
Else
    ConsoleWrite ( "no Process" & @Crlf )
EndIf

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

And where coming stdout.. In addition, I wish also use tasklist command since I wish to test data of tasks on other machine

Therefore my full code look like:

#include <Constants.au3>
For $i = 0 To 19 Step 1
If GUICtrlRead($avCheckID[$i]) = 1 Then
$_Run = @ComSpec & ' /c tasklist /S chayon"&$i&" /FI "IMAGENAME eq cmd.exe"'
ConsoleWrite ( ' $_Run : ' & $_Run & @Crlf )
$_Pid = Run ( $_Run, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD )
Dim $_StderrRead='', $_StdoutRead=''

While ProcessExists ( $_Pid )
    $_StdoutRead = StdoutRead ( $_Pid )
Wend

If StringInStr($_StdoutRead,"Image")=0 Then 
    ConsoleWrite("Process exist")
Else
    ConsoleWrite("Process not exist")
EndIf
EndIf 
Next

And loop being infinite in 1 case:

1. as you can see, loop run from 1 to 19 (it's check buttons and it's check if check box is sign with V)-so on 1st signed check box it run well and on the 2nd it stuck

in infinite loop here:

While ProcessExists ( $_Pid )
    $_StdoutRead = StdoutRead ( $_Pid )
Wend

The 2nd case it's stuck is while _RunDOS takes time due to process not exist (See more topic: timeout for _RunDOS)

Thanks a lot for your dedication!!

Noa :-)

Edited by autoitquestion

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