No announcement yet.

Help with "SHELL" statement

  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Originally posted by Mike Doty View Post
    ShellExecute runs asynchronously.
    He wants to redirect output to a file before continuing.

    To shell to wordpad.exe, SHELL "WRITE.EXE"
    Yep, Wordpad.exe is not normally in the PATH so invoking it from a CLI generally won't work. (( it's likely to be "Windows NT\Accessories" under both sets of %Program Files% directories)

    Write.exe is a stub in %WINDIR% that opens Wordpad. (It's a historical thing for backward compatibility dating back to when they replaced Write with Wordpad - back in Win95 )
    I've got no idea how ShellExecute manages to find Wordpad.exe

    Added: Doh! ShellExecute looks in the Registry - Wordpad is registered!


    • #22
      My code testing SHELL (post #17) worked calling the 32-bit 7z.exe from Windows 10 32-bit.
      MIchael brought up a good point, this might not work calling the 64-bit version of 7z.exe ?


      • #23
        The shell works with 32-bit version of 7z.exe and 64-bit version of 7z.exe from Windows 10 64-bit.
        Changed the path for 32-bit when using 64-bit Windows in this example.
        Note: The file "me.txt" is created no matter what so ISFILE("me.txt") was worthless.

        'MACRO mzip(sParms) = SHELL ENVIRON$("COMSPEC") + " /C ""C:\Program Files\7-Zip\7z.exe""" + " " + sParms,0
        MACRO mzip(sParms) = SHELL ENVIRON$("COMSPEC") + " /C ""C:\Program Files (x86)\7-Zip\7z.exe""" + " " + sParms,0
        FUNCTION PBMAIN AS LONG  'c:\zip\test.bas
         KILL "me.txt":KILL "":ERRCLEAR
         mzip("a *.*")
         mzip("l *.* > me.txt")
         SHELL "notepad.exe me.txt"
         KILL "me.txt":KILL "":ERRCLEAR
         zip "a *.*"
         zip "l *.* > me.txt"
         SHELL "notepad.exe me.txt"
         KILL "me.txt":KILL "":ERRCLEAR
         SHELL ENVIRON$("COMSPEC") + " /C ""C:\Program Files (x86)\7-Zip\7z.exe"" a *.*",0
         SHELL ENVIRON$("COMSPEC") + " /C ""C:\Program Files (x86)\7-Zip\7z.exe"" l *.* > me.txt",0
         SHELL "notepad.exe me.txt"
        SUB zip(s AS STRING)
         SHELL ENVIRON$("COMSPEC") + " /C ""C:\Program Files (x86)\7-Zip\7z.exe""" + " "  + s,0
        END SUB


        • #24
          This example adds files to "c:\test\" and extracts files to "c:\output"
          Not sure if "zip a" should be "-a0a" to always overwrite. Seems to work as is.
          #COMPILE EXE "c:\test\test.exe" 'test.bas
          %WndStyle=1 'Hide window=0.  While testing may want to use 1 in case input is needed.
          FUNCTION PBMAIN AS LONG  'save as c:\test\test.bas
           zip  "a c:\test\ c:\test\*"             'add all files in c:\test to archive c:\test\
           zip  "x -y c:\test\ -oc:\output"        '(x extract) (-y yes to overwrite all) (-o + folder 'no space after the o')
           zip  "l c:\test\  > c:\test\list.txt"   'redirect archive list to c:\test\list.txt
           SHELL "notepad.exe c:\test\list.txt"             'view c:\test\list.txt
          END FUNCTION
          FUNCTION zip(sParms AS STRING) AS LONG
           SHELL ENVIRON$("COMSPEC") + " /C ""C:\Program Files\7-Zip\7z.exe""" + " " + sParms,%WndStyle
          END FUNCTION
          Mike Doty
          Last edited by Mike Doty; 2 Nov 2021, 12:56 AM.


          • #25
            Originally posted by Robert Wallace View Post
            Maybe I am too old now (86.5) but I can't get either to work!!

            LOCAL mycommand AS STRING
            mycommand = $DQ + "C:\Program Files\7-Zip\7z.exe" + $DQ + " l C:\D_Drive\ > C:\D_Drive\1-test.txt"
            SHELL ENVIRON$("COMSPEC") + " /C " + mycommand, 0
            SHELL(ENVIRON$("COMSPEC") + " /C " + mycommand, 0)
            Well I'm quite young and they both work for me

            This might help identify where the problem is.. '
              mycommand = $DQ + "C:\Program Files\7-Zip\7z.exe" + $DQ + " l C:\D_Drive\ > C:\D_Drive\1-test.txt"
              SHELL ENVIRON$("COMSPEC") + " /K " + mycommand, 1
              ? ENVIRON$("COMSPEC") + " /K " + mycommand, %MB_SYSTEMMODAL, "Shell - "'
            .. + mycommand, 1 to shell the program in 'normal with focus' mode (not hidden as with ' mycommand, 0')

            " /C " tells the command processor "here comes a command and, when its finished executing, close the DOS shell it is running in".
            " /K " tells the command processor that a command follows, but it instructs it to leave the DOS session running so you can see any error messages.

            Rgds, Dave


            • #26
              Late last night my Camembert of a brain remembered that "SHELL" doesn't\may not work in "Debug " mode.

              As the code was embedded in a large program using Zlib I had inserted the test code in addition to the zlib code and so had to test in "Debug" mode.

              The code works perfectly as a piece of stand alone code.

              Many thanks for all your help - it finally got me to the right way of solving how to use 7-Zip.


              • #27
                Thank you, Mike!
                I hadn't paid much attention to this thread, just enough to get me thinking I might be able to use this feature of SHELL. I didn't read this thread far enough for dealing with Wordpad and I was not having any success but Write does the trick! I used the full path to the file I wanted to access, haven't yet tried it without the full path but I shall.
                SHELL "write.exe C:\PBWin10\semi\sspf_adj.rtf"
                Worked just the way I wanted it to. Thanks again.
                In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.