• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Process err- not a valid Win32 application

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,
I've an Oracle procedure which calls a Java program doing the task of executing operating system commands.
My Oracle procedure is below:

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
public static void executeCommand(String command) {
try {
String[] finalCommand;
{
finalCommand = new String[4];
finalCommand[0] = "C:\\windows\\system32\\cmd.exe";
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
}
final Process pr = Runtime.getRuntime().exec(finalCommand);
new Thread(new Runnable() {
public void run() {
try {
BufferedReader br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println("Process out :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
}
}
catch (IOException ioe) {
System.out.println("Exception caught printing process output.");
ioe.printStackTrace();
}
}
}).start();

new Thread(new Runnable() {
public void run() {
try {
BufferedReader br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println("Process err :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
}
}
catch (IOException ioe) {
System.out.println("Exception caught printing process error.");
ioe.printStackTrace();
}
}
}).start();
}
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
}
}

public static boolean isWindows() {
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
return true;
else
return false;
}

};
/

show errors java source "Host"

And I've created a PL/SQL wrapper for invoking the above procedure

CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';

Now I tried invoking the procedure to execute a VB script file.

SQL> DECLARE
BEGIN
Host_Command (p_command => 'C:\bhags\ondemand_odbc.vbs ICCW3053');
END;
/
Process err :C:\bhags\ondemand_odbc.vbs is not a valid Win32 application.
I'm not sure about this error.But same program works fine for simple OS commands like delete files,rename files etc.
Can someone help me out to fix this error please?

Thanks,
Bhagat
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try invoking "cmd" with your command-line options and your vbs file. I presume it doesn't work. If that's the case, this question has nothing to do with Java.

You need to investigate how to start a Visual Basic Script(that's what vbs means, isn't it?) program. A vbs file is not an executable, so you need to run it with whatever runs Visual Basic programs. A bit like the "java" command for running Java, I guess.

I guess you can run a vbs file directly from Windows Explorer. Look at what the file type association for vbs file extension is configured to do, in Windows Explorer. On my machine, it does the following: -



Where %1 is the vbs file, and %* are any command-line options you wanted to pass to your vbs program.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

This really isn't a Java question, but rather a Windows OS question. The error message is pretty clear, and it's telling you that your script is not runnable directly; you presumably have to execute the interpreter, and tell the interpreter to run the script, perhaps just by supplying the script as a command-line argument.

I'm not a Windows person, and don't have a machine handy to check, but in Windows I think you can right-click on a file icon and look at "Properties..." or some such; you should be able to find out about "file associations," meaning what the shell does when you double-click on the file. Whatever command line is used for the file association, that's what you want to run in your Runtime.exec() call.
 
Bhagat Singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Guys!!

Is there any way that I can invoke a VB script using a Java program?
Can someone help me with a sampel code?

Thanks,
Bhagat
 
Peter Chase
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The previous two responses tell you, yes.

You need to run the "WScript.exe" program using Runtime.exec(), passing the name of your script as the first argument and any arguments used by the script as the remaining arguments.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic