Page 1 of 1

Does RunProgram work on Windows 8 and 8.1?

Posted: Thu Nov 06, 2014 7:31 pm
by smacker
Hi;

Purchased pure basic almost a few years ago now and been using it for various things since then. never registered on the forum or posted here before so this is my first post. One of my first things I did with exploring pure basic back then and getting use to the various things about it was play around with the command prompt some via using RunProgram. So anyway, was looking through my old snippets of code and came across one of those things that works in Windows 7 64 and 32 bit but does not work at all in Windows 8 or 8.1. I expected it to continue working with Windows 8 so i just ran it in the compiler to check and was surprised it did not work. This is the code:

Code: Select all

Procedure.s GetIPAddrCmdPmt()
  
  workdir$ = "C:\Windows\System32\"
  
  Compilertrdns = RunProgram("nslookup.exe", " myip.opendns.com resolver1.opendns.com", workdir$, #PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
  Outns$ = ""
  If Compilertrdns
    While ProgramRunning(Compilertrdns)
      Outns$=ReadProgramString(Compilertrdns)
      keepdns$ = keepdns$ + Outns$ + #CRLF$
    Wend
    CloseProgram(Compilertrdns)
  EndIf
  Resultg$ = Trim(keepdns$, " ")
  Resulte$ = RemoveString(Resultg$, Chr(10), #PB_String_NoCase, 1)
  Resultf$ = RemoveString(Resulte$, Chr(13), #PB_String_NoCase, 1)
  Resultg$ = Trim(Resultf$, " ")
  Position = FindString(Resultg$, "Name", 1, #PB_String_NoCase)
  Resultxz$ = Mid(Resultg$, Position)
  Result1$ = RemoveString(Resultxz$, "myip.opendns.com", #PB_String_NoCase, 1)
  Result2$ = RemoveString(Result1$, "Name:", #PB_String_NoCase, 1)
  Result3$ = RemoveString(Result2$, "Address:", #PB_String_NoCase, 1)
  Result4$ = Trim(Result3$, " ")
  
  ProcedureReturn Result4$
  
EndProcedure

Debug GetIPAddrCmdPmt()


yes, I know its not the best but it was an early 'something to experiment with' code. Anyway, it starts up but just keeps running, never returns anything and never ends on Windows 8. Why is this? Is there something about the 'RunProgram' going on here, or is there some type of change for Windows 8 that renders the use of 'nslookup' here as I have it useless?

Windows 8 is new to me and havn't done anything with Pure Basic in windows 8 yet.

Like i said, works fine in windows 7 32 and 64 bit, but in Windows 8 nope. Any suggestions?

Thank You

Re: Does RunProgram work on Windows 8 and 8.1?

Posted: Thu Nov 06, 2014 7:55 pm
by PureGuy
Is there a nslookup.exe in side your C:\Windows\syswow64 folder ?

If Not try to run native version:

Compilertrdns = RunProgram("C:\Windows\Sysnative\nslookup.exe", ..

Re: Does RunProgram work on Windows 8 and 8.1?

Posted: Thu Nov 06, 2014 8:18 pm
by firace
Well, I don't know what the issue is (could it be some antivirus or security software trying to be "smart"?) but at least it works just fine here (Win 8.1 x32).

When I run your code, I instantly get this output: 91.182.192.68

Re: Does RunProgram work on Windows 8 and 8.1?

Posted: Thu Nov 06, 2014 8:20 pm
by PureGuy
This is the file redirection on x64 Windows.

You can read here about: File System Redirector

Re: Does RunProgram work on Windows 8 and 8.1?

Posted: Fri Nov 07, 2014 6:42 am
by Danilo
You can set workdir$ = "". The working directory is not the EXE path, it is the CurrentDirectory for the program you execute.

Works here, Windows 8.1 Ent, PB x86 and x64. Works only in ASCII mode.

Re: Does RunProgram work on Windows 8 and 8.1?

Posted: Tue Nov 11, 2014 9:37 pm
by smacker
@Danilo

What do you mean by "Works only in ASCII mode"?

Do you mean you can't read what it produces and it needs to be converted to read what it produces?

Re: Does RunProgram work on Windows 8 and 8.1?

Posted: Tue Nov 11, 2014 9:59 pm
by IdeasVacuum
I'm using RunProgram() to launch Help movies and PDF's from my Unicode apps - works fine on Windows 8.1

Re: Does RunProgram work on Windows 8 and 8.1?

Posted: Wed Nov 12, 2014 7:15 am
by Danilo
smacker wrote:@Danilo

What do you mean by "Works only in ASCII mode"?
My output in Unicode mode:

Code: Select all

???›????????????????†???????????›†?????????????›?????????
With ASCII compiler mode I get my IP address.

I thought this is because nslookup.exe is an ASCII program and outputs ASCII,
and your PB program reads Unicode strings.
In this case, you would have to use ReadProgramData() and PeekS() the ASCII data
to convert it into an Unicode PB string. That's for PB < 5.3x, for example the 5.2x LTS.

Starting with PB 5.30 you can use the flag #PB_Ascii:

Code: Select all

- Added: 'Format' parameter to Read/WriteProgramString, WriteProgramStringN() and ReadProgramError()
So you would probably write:

Code: Select all

    While ProgramRunning(Compilertrdns)
      Outns$=ReadProgramString(Compilertrdns, #PB_Ascii)
      keepdns$ = keepdns$ + Outns$ + #CRLF$
    Wend
to catch the correct output from ASCII programs.

Looking at the last few lines, I see now your problem:
smacker wrote:Anyway, it starts up but just keeps running, never returns anything and never ends on Windows 8. Why is this?
It is because ReadProgramString() is a blocking operation:
PB Help wrote:Syntax

Result$ = ReadProgramString(Program)

Description

Reads a line from the output (stdout) of the given program. This function waits until there is data available to read from the program.
To prevent this wait, AvailableProgramOutput() may be used first to check if there is something to read
So better check with AvailableProgramOutput():

Code: Select all

    While ProgramRunning(Compilertrdns)
      If AvailableProgramOutput(Compilertrdns)
        Outns$=ReadProgramString(Compilertrdns);, #PB_Ascii)
        keepdns$ = keepdns$ + Outns$ + #CRLF$
      EndIf
    Wend
This should not hang anymore. If you don't get any output, check also ReadProgramError().

Re: Does RunProgram work on Windows 8 and 8.1?

Posted: Wed Nov 12, 2014 11:50 am
by smacker
@Danilo

Yep, that solved the issue. Thank You :) Had to take it to someone else's windows 8.1 machine to check though as mine is down right now due to a failed hard drive but it did not work on theirs either until I did as you stated, and now it works.

Its odd though, some people said it worked for them on windows 8 and 8.1. It would not work for me on the Windows 8 system (before the hard drive failed), but worked fine in Windows 7. I wonder what the differences are that the code (without your changes) would cause it to work on some Windows 8 systems but not on others? Its very odd.

Thank You :)