Announcement

Collapse
No announcement yet.

Shell Output redirection

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Shell Output redirection

    When I run the following command from a DOS prompt it works fine.
    When I run it using SHELL it gives me conflicting switches.
    Do you have any idea why?

    NET USE LPT1: /DELETE 1>NUL 2>NUL

    I have read a microsoft technote that explains that you can
    redirect both stdout and stderr from the command line using the
    syntax.

    The technote was Q110930 and can be found at support.microsoft.com


    ------------------

  • #2
    Interesting. I'm not sure you want "1>" in place of ">" unless you're using
    the "2>&1" syntax, though-- it's not clear what's going on there.

    The previous note about "which command shell" still applies. Odds are, stderr
    redirection only works with CMD.EXE, not COMMAND.COM-- which may be the
    problem here.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      Needed to shell without showing output from a 3rd party program.
      Noticed that > NUL doesn't work and >NULL creates a file named "NULL"

      test.exe > NUL 2>&1

      The above command creates a file named &1



      Creating a file prevents output to screen, but would like to eliminate the file.
      org$ = org$ + " > NULL" 'create a file named NULL (or anything.)

      Tried these:
      'org$ = org$ + " > NUL 2>&1"
      'org$ = org$ + " 2&1 >NUL"
      'org$ = org$ + " 2>&1"
      'org$ = org$ + " NUL 2>&1"
      'org$ = org$ + " >> NUL 2>&1"
      'org$ = org$ + " >nul 2>nul"
      'org$ = org$ + " >nul: 2>nul:"
      Shell Org$


      Last edited by Mike Doty; 10 Apr 2017, 12:01 AM.

      Comment


      • #4
        As your program "knows" the name of the file created by redirecting output of 3rd party program, just KILL that file when SHELL is done.
        Dale

        Comment


        • #5

          > I noticed that > NUL doesn't work and >NULL creates a file named "NULL"

          '> NUL' can never work die to the space following ">" And you'd need to correct to "NUL" instead of "NULL."

          Or, you may have an older "true" MS-DOS system which does not recognize the symbols with the ampersand (too new!).

          Alternately... you don't have to use SHELL... there is an MS-DOS interrupt service you can call (using CALL INTERRUPT) which IIRC does allow you to override standard handles (much as is supported by the Windows' functions CreateProcess() and ShellExecuteEx()) when executing program file.

          You might also look at the behavior of the EXEC and RUN functions in PB/DOS.

          All in all, I kind of like "redirect output to known file and delete file when done with it" best of all.

          This may help..
          Code:
          FUNCTION GetTempWorkFileName (szPrefix AS ASCIIZ * 4, szTempFile AS ASCIIZ * %MAX_PATH) AS LONG
             ' returns: 0 = success, the temp file name is in szTempFile (fully qualified)
             '        other = System error number
             LOCAL szTempPrefix AS ASCIIZ * 4   ' 3 + null
             LOCAL szTempPath   AS ASCIIZ * %MAX_PATH
             LOCAL Stat AS LONG
             szTempPrefix = szPrefix     ' not that I care, but...
             Stat =  GetTempPath(SIZEOF(szTempPath), szTempPath)
             IF ISTRUE Stat THEN    ' GetTempPathSucceeded
                 Stat = GetTempFileName (szTempPath, szTempPrefix, 0&, szTempFile)
             END IF
             IF ISTRUE Stat THEN  ' function succeeded, return zero
                FUNCTION = 0
             ELSE
                FUNCTION = GetLastError  ' GetTempFileName returns non-zero on success
             END IF
          END FUNCTION
          MCM

          Michael Mattias
          Tal Systems Inc.
          Racine WI USA
          mmattias@talsystems.com
          http://www.talsystems.com

          Comment


          • #6
            have read a microsoft technote that explains that you can redirect both stdout and stderr from the command line using the syntax.
            That's true... but it does not guarantee the target program's output will go there... output only goes to the redirected place if the target program is writing to stdout/stderr.
            Michael Mattias
            Tal Systems Inc.
            Racine WI USA
            mmattias@talsystems.com
            http://www.talsystems.com

            Comment


            • #7
              FWIW..

              Interrupt 21h service 4Bh = execute program.
              Interrupt 21h service 45H = duplicate handle
              Interrupt 21h service 46H = redirect handle
              Michael Mattias
              Tal Systems Inc.
              Racine WI USA
              mmattias@talsystems.com
              http://www.talsystems.com

              Comment

              Working...
              X