Stoppt die Vorratsdatenspeicherung! Jetzt klicken & handeln!Willst du auch bei der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:

six demon bag

Wind, fire, all that kind of thing!


Using the DB2 Command Line Processer from PowerShell

Even for DB2 10.5 the official documentation says to use the db2cmd command for a Command Line Processor enabled environment on Windows:

On Windows operating systems, db2cmd command opens the CLP-enabled DB2® window, and initializes the DB2 command line environment.

However, being able to use PowerShell instead of db2cmd would be much nicer, since the former is far more versatile in practically every respect (control structures, output processing, file handling, etc.).

And it's actually rather simple, as I found out recently when reading this article. All that's required is setting one environment variable:

PS C:\> db2 'connect to sample'
DB21061E  Command Line Environment is not initialized.
PS C:\> Set-Item -Path env:DB2CLP -Value '**$$**'
PS C:\> db2 'connect to sample'

   Database Connection Information

 Database server        = DB2/NT64 10.5.1
 SQL authorization ID   = USERNAME
 Local database alias   = SAMPLE

PS C:\> _

Put the command in your profile to CLP-enable all your PowerShell prompts:

PS C:\> "Set-Item -Path env:DB2CLP -Value '**$$**'" >> $profile

Posted 01:38 [permalink]