DB2 statements in a batch file + redirect output to file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nananana

    DB2 statements in a batch file + redirect output to file

    Hi.
    I have 2 DB2 statements:

    connect
    select

    How can I create a batch file and redirect the output to a file?

    I would like something like this:

    run-select.cmd C:\select-output.txt

    TIA

  • Serge Rielau

    #2
    Re: DB2 statements in a batch file + redirect output to file

    Nananana wrote:
    Hi.
    I have 2 DB2 statements:
    >
    connect
    select
    >
    How can I create a batch file and redirect the output to a file?
    I would start with an edito.
    Then
    db2 -tvf <file output.txt

    There also is a -z option with the same effect as >

    Cheers
    Serge


    --
    Serge Rielau
    DB2 Solutions Development
    IBM Toronto Lab

    WAIUG Conference

    Comment

    • Gert van der Kooij

      #3
      Re: DB2 statements in a batch file + redirect output to file

      In article <1169017820.596 611.297250@11g2 000cwr.googlegr oups.com>,
      dnoam@il.ibm.co m says...
      Hi.
      I have 2 DB2 statements:
      >
      connect
      select
      >
      How can I create a batch file and redirect the output to a file?
      >
      I would like something like this:
      >
      run-select.cmd C:\select-output.txt
      >
      TIA
      >
      >
      Check the docs for a full description about how to use the DB2 Command
      Line Processor at http://tinyurl.com/yqxcva

      Comment

      • Nananana

        #4
        Re: DB2 statements in a batch file + redirect output to file

        Serge, thanks.
        This is what I did:
        The batch file has a single line -

        db2 connect ...
        >From the db2 CLP:
        C:\>db2 -tvf c:\db2-dup.cmd

        DB21007E End of file reached while reading the command.

        Please advice.

        Thanks and regards,

        Serge Rielau wrote:
        Nananana wrote:
        Hi.
        I have 2 DB2 statements:

        connect
        select

        How can I create a batch file and redirect the output to a file?
        I would start with an edito.
        Then
        db2 -tvf <file output.txt
        >
        There also is a -z option with the same effect as >
        >
        Cheers
        Serge
        >
        >
        --
        Serge Rielau
        DB2 Solutions Development
        IBM Toronto Lab
        >
        WAIUG Conference
        http://www.iiug.org/waiug/present/Fo...Forum2006.html

        Comment

        • Mark A

          #5
          Re: DB2 statements in a batch file + redirect output to file

          "Nananana" <dnoam@il.ibm.c omwrote in message
          news:1169446627 .764877.178150@ q2g2000cwa.goog legroups.com...
          Serge, thanks.
          This is what I did:
          The batch file has a single line -
          >
          db2 connect ...
          >
          >>From the db2 CLP:
          >
          C:\>db2 -tvf c:\db2-dup.cmd
          >
          DB21007E End of file reached while reading the command.
          >
          Please advice.
          >
          Thanks and regards,
          When you run a script with "db2 -tvf file-name"
          you do not include "db2" in any of the commands within the script. So just
          put:

          connect to database-name;

          in your script (note the semi-colon at the end of each command). This
          assumes that you have authority to connect with your current Windows userid,
          otherwise you must specify a different user and password in the connect
          command.


          Comment

          • Nananana

            #6
            Re: DB2 statements in a batch file + redirect output to file

            Great - thanks.
            It works now..


            Mark A wrote:
            "Nananana" <dnoam@il.ibm.c omwrote in message
            news:1169446627 .764877.178150@ q2g2000cwa.goog legroups.com...
            Serge, thanks.
            This is what I did:
            The batch file has a single line -

            db2 connect ...
            >From the db2 CLP:
            C:\>db2 -tvf c:\db2-dup.cmd

            DB21007E End of file reached while reading the command.

            Please advice.

            Thanks and regards,
            >
            When you run a script with "db2 -tvf file-name"
            you do not include "db2" in any of the commands within the script. So just
            put:
            >
            connect to database-name;
            >
            in your script (note the semi-colon at the end of each command). This
            assumes that you have authority to connect with your current Windows userid,
            otherwise you must specify a different user and password in the connect
            command.

            Comment

            • Nananana

              #7
              Re: DB2 statements in a batch file + redirect output to file


              Excuse me.. more questions.
              Now I want to run this *** from a batch file *** (give the customer a
              desktop icon).
              This is what I get:

              C:\>db2 -tvf test.txt
              DB21061E Command line environment not initialized.

              Please advice.
              TIA

              Comment

              • Pierre Saint-Jacques

                #8
                Re: DB2 statements in a batch file + redirect output to file

                You seem to running this from a standard dos prompt command window,
                If you need to use the db2 interface, you must do so from a DB2 Command
                Window. which has the db2cmd command interpreter active.
                On your dos prompt line, issue: db2cmd

                This will open a new window which a DB2 command window and where you wil now
                be able to issue:
                db2 -tvf test.txt
                Just make sure that the test.txt file is in accessible within the PATH
                statement you are using.
                HTH, Pierre.

                --
                Pierre Saint-Jacques
                SES Consultants Inc.
                514-737-4515
                "Nananana" <dnoam@il.ibm.c oma écrit dans le message de news:
                1169622945.6402 57.164440@k78g2 00...legr oups.com...
                >
                Excuse me.. more questions.
                Now I want to run this *** from a batch file *** (give the customer a
                desktop icon).
                This is what I get:
                >
                C:\>db2 -tvf test.txt
                DB21061E Command line environment not initialized.
                >
                Please advice.
                TIA
                >

                Comment

                Working...