Jump to content

Return a sentence in cmd when launch from it


hcI
 Share

Recommended Posts

Hello I would like to know if there is a way to return a sentence in cmd when I launch from it (because I add arguments).

For example, diskpart.exe which help to manage the key and hdd connected, when you launch it with the parameter "/f" the app return a sentence saying that it don't recognize the parameter "/f" and it return the sentence in the cmd where i started the application, not a new one.

That's what I want to do but I couldn't find anything that would solve my problem on internet and on AutoIt like ConsoleWrite / ConsoleWriteError (don't work).

 

Thanks

Link to comment
Share on other sites

  • Moderators

@hcl, you can use StdOutRead, something like this:

#include <Constants.au3>

$net = Run(@ComSpec & " /c defrag.exe C:\ /A", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($net)
    If @error Then ExitLoop
        If $line <> "" Then ConsoleWrite($line & @CRLF)
Wend

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I understand now how std commands works but want I would like to do is not launching an app and then read what it return,

I would like to, when I run "MyAutoItApp.exe /example" the application will detect itself that /example is not a valid parameter and then write in the cmd where I executed "MyAutoItApp.exe /example" something like "/example is not a valid parameter". So it would look like that :

Global $own_process = "I would like to handle in this variable the process of this script when running"

If $CmdLine[0] > 0 Then
    If Not $CmdLine[1] = "/right" Then
        StdinWrite($own_process, $CmdLine[1] & " is not a valid parameter.") ; I don't know either if this would work as it is supposed to write in child process and not in "the one that launched the script"
        Exit
    Else
        StdinWrite($own_process, $CmdLine[1] & " is the valid parameter.") ; Same here...
        MsgBox(64, "", "The 1st parameter you typed was /right !")
        Exit
    EndIf
EndIf

 

Edited by hcI
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...