ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Running commands on the AS400 from Powershell via QCMDEXC

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

  • Running commands on the AS400 from Powershell via QCMDEXC

    This was sort of a "just because I can" type of thing. At any rate it works.
    I'm sure there are issues, I suspect the way I'm handling single quotes won't work in all cases for one. I figured you guys might find it interesting.

    http://pastebin.com/sHgRBpXX

  • #2
    Re: Running commands on the AS400 from Powershell via QCMDEXC

    nice.

    In version 7.1 and higher you can ignore the length parm but you need qsys2.

    Code:
    call qsys2.qcmdexc('DSPUSRPRF USRPRF(DEADMAN) OUTPUT(*PRINT)')
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: Running commands on the AS400 from Powershell via QCMDEXC

      Originally posted by DeadManWalks View Post
      nice.

      In version 7.1 and higher you can ignore the length parm but you need qsys2.

      Code:
      call qsys2.qcmdexc('DSPUSRPRF USRPRF(DEADMAN) OUTPUT(*PRINT)')
      Ahh yeah, I thought I remembered something like that. I'll have to check if our box has it.

      Comment


      • #4
        Re: Running commands on the AS400 from Powershell via QCMDEXC

        Actually, it's worked this way for a long time, long before IBM started distributing the QCMDEXC stored proc. Essentially any *PGM can be called in this way (including QSYS/QCMDEXC) without defining a DB2 stored proc as long as you don't need output parameter values.

        But in i 6.1 (or was it V5R4?) IBM started distributing an actual stored proc -- QSYS2.QCMDEXC(). It's actually overloaded so that there are two definitions.

        One accepts a command string as the first parameter and a numeric length value as the second parameter. That's defined as an external stored proc that uses QSYS/QCMDEXC to do the command execution. You can test it with STRSQL:
        Code:
        > call qsys2.qcmdexc ('sndmsg hi toml', 14)
          CALL statement complete.
        The second definition is a SQL stored proc, and it can be called in STRSQL like this:
        Code:
        > call qsys2.qcmdexc ('sndmsg hi toml')
          CALL statement complete.
        Or maybe better as:
        > call qcmdexc ('sndmsg hi toml')
          CALL statement complete.
        The SQL version doesn't need a length (even in i 6.1). The SQL in the stored proc calculates the LENGTH() and then passes it as a parm to QSYS2.QCMDEXC().
        Tom

        There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

        Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

        Comment


        • #5
          Please excuse this question as I am new to this - can someone please supply me with the line needed to call out the AS/400 to connect to it? Thank you in advance!

          Comment


          • #6
            If you are using powershell then the connection is shown in the code at the link provided.
            PHP Code:
                #Open connection to AS400
                
            $conn = New-Object System.Data.Odbc.OdbcConnection
                $conn
            .ConnectionString "Driver={iSeries Access ODBC Driver};System=AS400;Uid=USER;Pwd=PASS;"
                
            $conn.Open() 
            the smoking gnu

            Comment

            Working...
            X