Jump to content

Recommended Posts

Posted (edited)

How I searched for the hang-up place. I changed the code as follows.

; freezes randomly
#include <Date.au3>
#include <Constants.au3>

local $fDiff=0, $pid=0, $hTimer=0, $line=""

While 1
    ConsoleWrite('1 '&_NowTime()&@CRLF)
    $pid = Run("ipconfig", "", @SW_HIDE, 0x2)
    $line = ""
    ConsoleWrite('2 '&_NowTime()&@CRLF)
    $hTimer = TimerInit()
    While 1
        $fDiff = TimerDiff($hTimer)
        $line &= StdoutRead($pid)
        If @error or $fDiff>50 Then ExitLoop
    Wend
    ConsoleWrite('3 '&_NowTime()&@CRLF)
    if StringInStr($line,'0.1'&@CRLF)>1 then TraySetIcon("icon1.ico")
    if StringInStr($line,'0.2'&@CRLF)>1 then TraySetIcon("icon2.ico")
    ConsoleWrite('4 '&_NowTime()&@CRLF)
    sleep(20000)
    ConsoleWrite('5 '&_NowTime()&@CRLF)
WEnd

In general, in all cases of freezing, the last thing printed was, for example:

2 07:08:09

Something like that.

Edited by daledale
Posted

@daledale  I think your issue comes from the fact that you are not waiting for the stream to be ready to transmit correctly.  You should wait for the process to be up and running before reading the stream.  Here the right way to get the result of ipconfig.

#include <Date.au3>
#include <Constants.au3>

Local $pid, $line

While True
  ConsoleWrite('1 ' & _NowTime() & @CRLF)
  $pid = Run("ipconfig", "", @SW_HIDE, $STDERR_MERGED)
  ConsoleWrite('2 ' & _NowTime() & @CRLF)
  ProcessWaitClose($pid)
  $line = StdoutRead($pid)
  ConsoleWrite('3 ' & _NowTime() & StringLeft($line, 50) & @CRLF)
  ;If StringInStr($line, '0.1' & @CRLF) > 1 Then TraySetIcon("icon1.ico")
  ;If StringInStr($line, '0.2' & @CRLF) > 1 Then TraySetIcon("icon2.ico")
  ConsoleWrite('4 ' & _NowTime() & @CRLF)
  Sleep(2000) ; reduced sleep to get more occurences
  ConsoleWrite('5 ' & _NowTime() & @CRLF)
WEnd

 

Posted (edited)

Thanks for the answer. I don't want to challenge your competence in any way. I think when you wrote that "the stream is not ready to transmit" - you mean that the command RUN was not completely finished. If so, I want to focus your attention to - what is printed last, when it hangs (see my reply above).

43 minutes ago, Nine said:

@daledale  I think your issue comes from the fact that you are not waiting for the stream to be ready to transmit correctly.  You should wait for the process to be up and running before reading the stream.  Here the right way to get the result of ipconfig.

#include <Date.au3>
#include <Constants.au3>

Local $pid, $line

While True
  ConsoleWrite('1 ' & _NowTime() & @CRLF)
  $pid = Run("ipconfig", "", @SW_HIDE, $STDERR_MERGED)
  ConsoleWrite('2 ' & _NowTime() & @CRLF)
  ProcessWaitClose($pid)
  $line = StdoutRead($pid)
  ConsoleWrite('3 ' & _NowTime() & StringLeft($line, 50) & @CRLF)
  ;If StringInStr($line, '0.1' & @CRLF) > 1 Then TraySetIcon("icon1.ico")
  ;If StringInStr($line, '0.2' & @CRLF) > 1 Then TraySetIcon("icon2.ico")
  ConsoleWrite('4 ' & _NowTime() & @CRLF)
  Sleep(2000) ; reduced sleep to get more occurences
  ConsoleWrite('5 ' & _NowTime() & @CRLF)
WEnd

 

This is not worked for me. I need gateway's ip from ipconfig. The above version of the program with ipconfig output does not do this, $line variable does not contain any ip addresses at all.

ps I hope you saw the beginning of my reply on the previous page? There I provided three programs, one of which definitely works for me and overall my problem is solved. I just wanted to share a possible solution with the forum members. Now I don't have any problem related to this and my issue is, I repeat, solved.

Edited by daledale
Posted

Fine, I just want to state (for any future readers) that the way you are doing it is not appropriate and they (future readers) should use my method instead.

I have no idea why it does not work for you and with your attitude I will not investigate further the reason.

Here what $line content in my case :

3 08:34:41

Configuration IP de Windows


Carte Ethernet Ethernet :

   Suffixe DNS propre à la connexion. . . : 
   Adresse IPv6 de liaison locale. . . . .: fe80::a24a:aeb1:9219:3908%15
   Adresse IPv4. . . . . . . . . . . . . .: 10.0.0.234
   Masque de sous-réseau. . . . . . . . . : 255.255.255.0
   Passerelle par défaut. . . . . . . . . : 10.0.0.1

Carte Ethernet vEthernet (Ethernet) :

   Suffixe DNS propre à la connexion. . . : 
   Adresse IPv6 de liaison locale. . . . .: fe80::6d42:273d:f020:9264%27
   Adresse IPv4. . . . . . . . . . . . . .: 192.168.192.1
   Masque de sous-réseau. . . . . . . . . : 255.255.240.0
   Passerelle par défaut. . . . . . . . . : 
4 08:34:41

 

Posted (edited)
13 minutes ago, Nine said:

Fine, I just want to state (for any future readers) that the way you are doing it is not appropriate and they (future readers) should use my method instead.

Nothing against it, the choice is up to the end users. I don't insist on my decision exclusively.

13 minutes ago, Nine said:

I have no idea why it does not work

Checked again, your option really doesn't work for me. Again, I have win7x64 (maybe you have win10,11 and that's the reason) and also maybe the reason is that I do NOT have an English language windows.

1 16:43:50
2 16:43:50
3 16:43:50
IP Protocol Configuration for Windows


Ethernet
4 16:43:50
5 16:43:52
1 16:43:52
2 16:43:52
3 16:43:52
IP protocol configuration for Windows


Ethernet
4 16:43:52
13 minutes ago, Nine said:

and with your attitude I will not investigate further the reason.

I'm sorry. I translate all my replies with a translator - I wrote earlier. Perhaps there are some difficulties in translation and you thought I insulted you. I apologize again.

Edited by daledale
Posted
2 minutes ago, Nine said:

There is a stringleft (as I didn't want to show everything on every cycle).  Remove the stringleft and you will be fine !

Yeah, it's working now. Thank you.

ps Strange that I didn't realize it right away, indeed, stringleft)))

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
  • Recently Browsing   0 members

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