Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DAY 035: SHELL
#3
For the code examples obviously for Windows only, it might be better for the subject file to be placed in the system temporary directory. Because an user could decide to run a program like that in different directories each one having its "mytemp.tmp" or alike. Would have to deal with tedious concatenation making the code more difficult to read. Whoever is using an edition of QB64 that works on WindowsXP and earlier should look elsewhere. This code should work for Windows Vista and later and therefore no more worrying about a directory called "Documents and Settings" that long with spaces. The temporary path should begin with "C:\Users\<user's-name>\".

Edit: it could be spotty but this could work on Linux also except "wine" and space has to be added to the front of the whole entry, and all backslashes have to be doubled up. Maybe could use forward slash in place of backslash, but not for the ancient switches that should be delimited with hyphen instead. Also it's better to use "Z:" with Wine instead of "C:". The main problem remains being able to create a Windows EXE file in Linux to be able to test it more extensively.

Code: (Select All)
mypath$ = ENVIRON$("TEMP") + "\mytemp.tmp"
SHELL _HIDE "ipconfig>" + mypath$
OPEN mypath$ FOR BINARY AS #1
a$ = SPACE$(LOF(1))
GET #1, , a$
CLOSE #1
DO
    j = INSTR(LCASE$(a$), search$)
    IPAddy$ = MID$(a$, j)
    IPAddy$ = MID$(IPAddy$, 1, INSTR(IPAddy$, CHR$(13)) - 1)
    IPAddy$ = _TRIM$(MID$(IPAddy$, INSTR(IPAddy$, ":") + 1))
    IF j AND LEN(search$) > 0 THEN
        PRINT "Your IP Address is: "; IPAddy$
        EXIT DO
    ELSE
        SELECT CASE cnt
            CASE 0
                search$ = "ipv4 address"
            CASE 1
                search$ = "ip address"
            CASE 2
                search$ = "ipv4 "
            CASE 3
                search$ = "ipv4-address"
            CASE 4
                search$ = "ip-address"
            CASE 5
                search$ = "ipv4-"
            CASE ELSE
                PRINT "Sorry, can't find IP addy. Opening Notepad so you can find it..."
                SHELL _HIDE "START Notepad " + mypath$
                ' Other ways to write our SHELL...
                REM SHELL _HIDE _DONTWAIT "Notepad " + mypath$
                REM SHELL _HIDE _DONTWAIT "cmd /c Notepad " + mypath$
                REM SHELL _HIDE "cmd /c START Notepad " + mypath$
                EXIT DO
        END SELECT
    END IF
    cnt = cnt + 1
LOOP

I doubt that in this code anybody would need a "mytemp.tmp" dumped into the "Temp" directory deep in the user area. But we will never know.
Reply


Messages In This Thread
DAY 035: SHELL - by Pete - 12-16-2022, 02:10 AM
RE: DAY 035: SHELL - by mnrvovrfc - 12-16-2022, 11:15 AM
RE: DAY 035: SHELL - by mnrvovrfc - 12-16-2022, 11:26 AM
RE: DAY 035: SHELL - by Pete - 12-16-2022, 03:45 PM



Users browsing this thread: 2 Guest(s)