1

I have the following scenario:
1. I have a Powershell script foo.ps1
2. Within this script, I want to call bar.jar
3. Bar.jar runs a query against an Oracle DB
4. The result of that query should be passed back to foo.ps1

The reason why I am having the jar to do the DB call is because I have the 32 bit Oracle libraries installed, however I cannot force Powershell to run in 32 bit mode. I already tried solutions like
How to execute powershell script in 64 bit machine?
However although it says in the console that it switches to 32 bit mode, I still get the exception "Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."

Cheers!

Community
  • 1
  • 1
  • The version of powershell you are running should not matter since it is just launching the java executable. Are you sure you are launching the 32-bit version of java? – zdan May 20 '13 at 04:09

1 Answers1

2

I've used the 32 bit ODAC libraries from a 32 bit PowerShell console.

[System.Reflection.Assembly]::LoadWithPartialName('Oracle.DataAccess')

After importing with the above line, you can create the Oracle objects and connect to the database and run queries.

You can also run this in a 32 bit background job.

Start-Job -ScriptBlock $oracle_script_block -RunAs32 | Wait-Job | Receive-Job

If you still want to use the Java code you can run it like this:

$output = & java.exe -jar <oracle JAR>
Write-Host "Exit code: $LASTEXITCODE"
Write-Host "Output: $output"

As zdan points out, make sure java.exe is 32 bit.

& java.exe -version
Andy Arismendi
  • 50,577
  • 16
  • 107
  • 124