Jump to content

cmd read command from consolread


Recommended Posts

@jos it's stuck on ( please enter website) when i try to use keyboard to enter any think it does not writing any think i test it on 2 machines the same issue it work fine inside SciTE

Edited by hani-dev
Link to comment
Share on other sites

compiled as x64, same result. All what you type does not appear .... then, typing ctrl-c the script ends, the dos prompt reappears, and all what you had typed appears next to the dos prompt...

 

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

3 minutes ago, Chimp said:

compiled as x64, same result. All what you type does not appear .... then, typing ctrl-c the script ends, the dos prompt reappears, and all what you had typed appears next to the dos prompt...

yes @Jos thats the problem !! how we can solve it 

Link to comment
Share on other sites

29 minutes ago, Chimp said:

Yesterday I tried the @Jos's script from post #13 on win10 x64 and it worked, today I tried it on win7 x64 and is not working...

im using windows 7 x64 and it's not working i never test it on windows 10 

Edited by hani-dev
Link to comment
Share on other sites

a) I don't know why @COMSPEC is being called for a command (ping) that's external to cmd.exe

Run("Ping www.google.com", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

should work.

 

Second ConsoleRead() doesn't work as expected from compiled console applications.

If you piped it through "more" it would work. You used to be able to open the file "con" as raw, but that stopped working. Check out this UDF:

I also found this snippit that opens console as raw using API:

;https://www.autoitscript.com/forum/topic/107951-help-with-_winapi_createfile-function-and-raw-mode/?do=findComment&comment=761172
#AutoIt3Wrapper_Change2CUI=y
#include <WinAPI.au3>

$sResponse = _ConsoleInput("Please input some text: ")
ConsoleWrite("You Entered: " & $sResponse & @CRLF)

Func _ConsoleInput($sPrompt)
    If Not @Compiled Then Return SetError(1, 0, 0) ; Not compiled

    ConsoleWrite($sPrompt)

    Local $tBuffer = DllStructCreate("char"), $nRead, $sRet = ""
    Local $hFile = _WinAPI_CreateFile("CON", 2, 2)

    While 1
        _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nRead)
        If DllStructGetData($tBuffer, 1) = @CR Then ExitLoop
        If $nRead > 0 Then $sRet &= DllStructGetData($tBuffer, 1)
    WEnd

    _WinAPI_CloseHandle($hFile)
    Return $sRet
EndFunc

 

Edited by TurionAltec
Link to comment
Share on other sites

6 minutes ago, hani-dev said:

im using windows 7 x64 and it's now working ......

 

5 minutes ago, hani-dev said:

@jos no it's not working ......

 

..... :lol: ..... funny

 

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

 

;https://www.autoitscript.com/forum/topic/107951-help-with-_winapi_createfile-function-and-raw-mode/?do=findComment&comment=761172
#AutoIt3Wrapper_Change2CUI=y
#include <WinAPI.au3>

$sResponse = _ConsoleInput("Please input some text: ")
ConsoleWrite("You Entered: " & $sResponse & @CRLF)

Func _ConsoleInput($sPrompt)
    If Not @Compiled Then Return SetError(1, 0, 0) ; Not compiled

    ConsoleWrite($sPrompt)

    Local $tBuffer = DllStructCreate("char"), $nRead, $sRet = ""
    Local $hFile = _WinAPI_CreateFile("CON", 2, 2)

    While 1
        _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nRead)
        If DllStructGetData($tBuffer, 1) = @CR Then ExitLoop
        If $nRead > 0 Then $sRet &= DllStructGetData($tBuffer, 1)
    WEnd

    _WinAPI_CloseHandle($hFile)
    Return $sRet
EndFunc

@jos , @Chimp , @TurionAltec how i can edit this script to take what i input in _consoleinput ( www.google.com) and excute ping on it 
 

@Subz can u help me ?

Edited by hani-dev
Link to comment
Share on other sites

#AutoIt3Wrapper_Change2CUI=y
#include <WinAPI.au3>
#include <AutoItConstants.au3>
$sResponse = _ConsoleInput("Please enter website:")

ConsoleWrite("pinging:" & $sResponse&@CRLF)
$DOS = Run("Ping " & $sResponse, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While ProcessExists($DOS)
    $Message = StdoutRead($DOS)
    ConsoleWrite($Message)
WEnd
$Message = StdoutRead($DOS)
If $Message <> "" Then ConsoleWrite($Message)

;https://www.autoitscript.com/forum/topic/107951-help-with-_winapi_createfile-function-and-raw-mode/?do=findComment&comment=761172
Func _ConsoleInput($sPrompt)
    If Not @Compiled Then Return SetError(1, 0, 0) ; Not compiled

    ConsoleWrite($sPrompt)

    Local $tBuffer = DllStructCreate("char"), $nRead, $sRet = ""
    Local $hFile = _WinAPI_CreateFile("CON", 2, 2)

    While 1
        _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nRead)
        If DllStructGetData($tBuffer, 1) = @CR Then ExitLoop
        If $nRead > 0 Then $sRet &= DllStructGetData($tBuffer, 1)
    WEnd

    _WinAPI_CloseHandle($hFile)
    Return $sRet
EndFunc

 

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...