Shell commands from JSP after Forms migration

During application migration from forms 9i to JSP & BC4J, I have to code the following Forms code into my JSP application.This is for a button pressed trigger.
DECLARE
RENAME_STRING VARCHAR2(120):= 'RENAME C:\BRC\PDATA' ||:DRAWING_ACCOUNTS.ACCOUNT_ID|| '.TXT P' || :DRAWING_ACCOUNTS.ACCOUNT_ID || TO_CHAR(SYSDATE,'DDMMYY')|| '.txt';
BEGIN
HOST( RENAME_STRING, no_screen );
web.show_document( 'http://hostname/selectfile.html', '_new');
     IF NOT Form_Success THEN
          Message('Error -- File not Renamed.');
     END IF;
END;
How can I do this simple sending of OS commands in JSP, any ideas?

Hi,
Not only rename commands but I have to pass several other os commands like 'sqlldr' for data upload as well. Therefore, I need a reusable piece of code for that. I have acheived some way for that using the following code.
put the following file in that package.
package BankrecBC4J;
import java.util.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.zip.*;
class StreamGobbler extends Thread
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
this.is = is;
this.type = type;
public void run()
try
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
ioe.printStackTrace();
public class GoodWindowsExec
private static final boolean NATIVE_COMMANDS = true;
//Allow browsing and file manipulation only in certain directories
     private static final boolean RESTRICT_BROWSING = false;
//If true, the user is allowed to browse only in RESTRICT_PATH,
//if false, the user is allowed to browse all directories besides RESTRICT_PATH
private static final boolean RESTRICT_WHITELIST = false;
//Paths, sperated by semicolon
//private static final String RESTRICT_PATH = "C:\\CODE;E:\\"; //Win32: Case important!!
     private static final String RESTRICT_PATH = "/etc;/var";
     * Command of the shell interpreter and the parameter to run a programm
     private static final String[] COMMAND_INTERPRETER = {"cmd", "/C"}; // Dos,Windows
     //private static final String[] COMMAND_INTERPRETER = {"/bin/sh","-c"};      // Unix
     * Max time in ms a process is allowed to run, before it will be terminated
private static final long MAX_PROCESS_RUNNING_TIME = 30 * 1000; //30 seconds
     //Normally you should not change anything after this line
     //Change this to locate the tempfile directory for upload (not longer needed)
     private static String tempdir = ".";
     private static String VERSION_NR = "1.1a";
     private static DateFormat dateFormat = DateFormat.getDateTimeInstance();
public GoodWindowsExec(String g)
System.out.println(" hello " + g);
/*if (g.length < 1)
System.out.println("USAGE: java GoodWindowsExec <cmd>");
System.exit(1);
try
String osName = System.getProperty("os.name" );
String[] cmd = new String[3];
System.out.println("here ");
if( osName.equals( "Windows NT" ) )
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = g;
else if( osName.equals( "Windows 2000" ) )
System.out.println("Windows 2000");
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = g;
else if( osName.equals( "Windows XP" ) )
System.out.println("Windows XP");
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = g;
else if( osName.equals( "Windows 95" ) )
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = g;
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]);
Process proc = rt.exec(cmd);
     * Starts a native process on the server
     *      @param command the command to start the process
     *     @param dir the dir in which the process starts
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
     * Converts some important chars (int) to the corresponding html string
     static String conv2Html(int i) {
          if (i == '&') return "&amp;";
          else if (i == '<') return "&lt;";
          else if (i == '>') return "&gt;";
          else if (i == '"') return "&quot;";
          else return "" + (char) i;
static String startProcess(String command, String dir) throws IOException {
          StringBuffer ret = new StringBuffer();
          String[] comm = new String[3];
          comm[0] = COMMAND_INTERPRETER[0];
          comm[1] = COMMAND_INTERPRETER[1];
          comm[2] = command;
          long start = System.currentTimeMillis();
          try {
               //Start process
               Process ls_proc = Runtime.getRuntime().exec(comm, null, new File(dir));
               //Get input and error streams
               BufferedInputStream ls_in = new BufferedInputStream(ls_proc.getInputStream());
               BufferedInputStream ls_err = new BufferedInputStream(ls_proc.getErrorStream());
               boolean end = false;
               while (!end) {
                    int c = 0;
                    while ((ls_err.available() > 0) && (++c <= 1000)) {
                         ret.append(conv2Html(ls_err.read()));
                    c = 0;
                    while ((ls_in.available() > 0) && (++c <= 1000)) {
                         ret.append(conv2Html(ls_in.read()));
                    try {
                         ls_proc.exitValue();
                         //if the process has not finished, an exception is thrown
                         //else
                         while (ls_err.available() > 0)
                              ret.append(conv2Html(ls_err.read()));
                         while (ls_in.available() > 0)
                              ret.append(conv2Html(ls_in.read()));
                         end = true;
                    catch (IllegalThreadStateException ex) {
                         //Process is running
                    //The process is not allowed to run longer than given time.
                    if (System.currentTimeMillis() - start > MAX_PROCESS_RUNNING_TIME) {
                         ls_proc.destroy();
                         end = true;
                         ret.append("!!!! Process has timed out, destroyed !!!!!");
                    try {
                         Thread.sleep(50);
                    catch (InterruptedException ie) {}
          catch (IOException e) {
               ret.append("Error: " + e);
          return ret.toString();
In the first line of the JSP file include the package
<%@page import="BankrecBC4J.*" %>
and call
it this way:from the jsp page
new GoodWindowsExec ("calc"); //
which should open up the calciulator, and should do for other os commands as well.
Thanks

Similar Messages

  • Execute shell command from within pascal code

    Hello there,
    I am trying to execute a shell command from within my pascal code. I use XCode together with FreePascal. I have tried something like:
    exec ('program', 'options');
    adding the 'Dos' unit to the Uses clause of my program.
    Thus, e.g.,
    exec ('mkdir', '/A')
    to create a directory with the name 'A'.
    However, my attempts so far were unsuccessful. Can anyone help me on this, and perhaps provide a simple example of how to do it right?
    Thank you in advance,
    Shane

    In the mean time, I found the problem myself. I am just posting the solution here for anyone that is interested. My original solution was correct, in that the 'Dos' Unit must be added, and that the right command is 'exec'. There was however a problem with the correct path to the program that I wanted to invoke. In the shell, this program was accessible from anywhere. However, in the 'exec' command, the full path to the program must be given. Since I am not a Unix expert, I don't know the reason for this.
    So, in summary, the solution is:
    Uses Dos;
    begin
    exec ('full path to program', 'program options');
    e.g.: exec ('/bin/sh', '/run.sh') to process the commands in the file /run.sh
    end
    Hope this may be of help to anyone else.
    Shane
    Mac OS X (10.3.9)
    Mac OS X (10.3.9)
    Mac OS X (10.3.9)

  • Execute shell command from Java

    Hi all,
    I need some idea for executing shell script from Java programe.
    For example i have start.sh script in /tmp/start.sh  folder of unix server.
    I want to execute shell script from local java code.
    Any idea on this.

    Hi,
           Read the following articles/posts, maybe this could help you:
          How to execute shell command from Java
    Running system commands in Java applications | java exec example | alvinalexander.com
    Want to invoke a linux shell command from Java - Stack Overflow

  • How to run a DOS command from an Oracle form.

    How can I run a DOS command from an Oracle form (i.e. open the calculator located at c:\windows\system32\calc.exe)?

    first of all get the environment variable for the c:\windows\system32 direcotry for any of the windows
    you can use get variable from the ora env package
    now cancat the system32 variable with the calc.exe string
    now pass the string with host command as parameters
    this process will work for all type of windows.

  • Create Form Beans from JSP/HTML forms

    In the Builder certification objectives, there is one called "Create Form Beans from JSP/HTML forms". How can I do that? How can I create a form beam starting from the JSP form or HTML form?

    Guys, no one from forum can answer this question?

  • How to Execute Power Shell Command From Windows Application.

    Hi All Experts,
    I want to execute power shell commands from my windows application.
    Is it possible ?
    Please let me know your comments..
    Thanks.

    I have not tried this, but apprently it is easy as in the sample pasted below. please see this article for more details
    http://geekswithblogs.net/Norgean/archive/2012/09/19/running-powershell-from-within-sharepoint.aspx.
    Let me know how it goes...
    public string RunPowershell(string powershellText, SPWeb web, string param1, string param2) {
    // Powershell ~= RunspaceFactory - i.e. Create a powershell context
    var runspace = RunspaceFactory.CreateRunspace();
    var resultString = new StringBuilder();
    try
    // load the SharePoint snapin - Note: you cannot do this in the script itself (i.e. add-pssnapin etc does not work)
    PSSnapInException snapInError;
    runspace.RunspaceConfiguration.AddPSSnapIn("Microsoft.SharePoint.PowerShell", out snapInError);
    runspace.Open();
    // set a web variable.
    runspace.SessionStateProxy.SetVariable("webContext", web);
    // and some user defined parameters
    runspace.SessionStateProxy.SetVariable("param1", param1);
    runspace.SessionStateProxy.SetVariable("param2", param2);
    var pipeline = runspace.CreatePipeline();
    pipeline.Commands.AddScript(powershellText);
    // add a "return" variable
    pipeline.Commands.Add("Out-String");
    // execute!
    var results = pipeline.Invoke();
    // convert the script result into a single string
    foreach (PSObject obj in results)
    resultString.AppendLine(obj.ToString());
    finally
    // close the runspace
    runspace.Close();
    // consider logging the result. Or something.
    return resultString.ToString();
    Ok. We've written some code. Let us test it.
    var runner = new PowershellRunner();
    runner.RunPowershellScript(@"
    $web = Get-SPWeb 'http://server/web' # or $webContext
    $web.Title = $param1
    $web.Update()
    $web.Dispose()
    ", null, "New title", "not used");
    -Sangeetha

  • Incorporate shell commands from forms

    How to incorporate unix shell commands(eg. ls, cp) from forms9i?
    In Windows environment,it is possible by issuing
    host command(eg. HOST('DIR >k.lis') -- it moves the list of files from Oracle9i/forms90 path to a file k.lis).
    The same thing I have to do in a unix environment.

    I think you have the wrong forum. This forum has to do
    with the UIX technology inside of JDeveloper. Your
    question seems to have to do with UNIX or forms. I can't
    tell which.

  • Calling a shell command from LabVIEW

    Platform:
    Labview 8.6 on Fedora 10.
    The VI is generating some data that I wish to convert to a form that a Windows user can work with (with CR/LF as the EOL). Is there a way to issue a shell command (specifically: $unix2dos <generated file name>) from within labview ? 
    Solved!
    Go to Solution.

    Hi,
    have you tried the "System Exec" function? According to context help it should work on UNIX too...
    Btw. you have asked a related question in an other thread. Wouldn't converting the string data in the VI itself work? Or making a special VI for that purpose and enable the conversion by a switch (like "Win compatible format?")?
    Message Edited by GerdW on 02-13-2010 09:38 AM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Calling JSP from Forms and going back from JSP to Forms

    Hi,
    We are calling JSP from Forms 6i using show_document
    I'd like to go back to tha calling Form from the JSP.
    How can I construct the URL that would lead me back to the same Form and Forms session where the JSP was called from?
    Thanks,
    Arpad

    Thanks Shay,
    works for me too...
    Now:
    when I use the "Back" button of my IE to go back from JSP to the Forms session, it works for Jinitiator 1.1.8.19, but if I use Jinitiator 1.3 I got hung...
    Any ideas how could I make it work from Jinit 1.3?
    Thanks again/
    Regards,
    Arpad

  • How can i call shell command in JSP?

    My OS is Linux, and my WWW server is Tomcat,
    can i call shell command , such as gcc or setup,
    If yes, how can i? Would you give a source example?
    Thank you!

    Hi,
    I did this simple class to launch a process and after the cose there is an example to use it:
    import java.io.*;
    import java.util.*;
    public class ProcessExec {
    private String[] command;
    private StreamGobbler errorGobbler;
    private StreamGobbler outputGobbler;
    public ProcessExec() {
    public ProcessExec ( String[] command) {
    this.command = command;
    this.errorGobbler = null;
    this.outputGobbler = null;
    public String[] getCommand() {
    return ( this.command );
    public void setCommand( String[] command ) {
    this.command = command;
    public void exec() {
    try{
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(this.command);
    // any error message?
    errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
    // any output?
    outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    }catch (Throwable t){
    t.printStackTrace();
    }//catch
    public String getErrorMessage() {
    while ( this.errorGobbler.isAlive() ) {;}
    return ( this.errorGobbler.getResult().toString() );
    public String getOutputMessage() {
    while ( this.outputGobbler.isAlive() ) {;}
    return ( this.outputGobbler.getResult().toString() );
    } // ProcessExec
    Example to use it:
    try {
    ProcessExec pe = new ProcessExec( command );
    pe.exec();
    errorMessage = pe.getErrorMessage();
    outputMessage = pe.getOutputMessage();
    } catch ( Exception e ) {
    System.out.println (e);
    As you can guess the string "command" must be the command you have to launch and errorMessage and outputMessage will contain the error and the output that the process will generate.
    Try it; i hope this will help you.
    Cheers.
    Stefano

  • Invoking a shell script from JSP

    Hi,
    I am trying to invoke a shell script from within my JSP. I need to pass a few parameters to this shell script also. The shell script then returns a string value to the JSP. Any ideas, how to acheive this? I would appreciate any help.
    Thanks,
    Fauzia

    implement a method somewhere that uses Runtime.exec() internally. see here:
    http://java.sun.com/j2se/1.3/docs/api/index.html
    robert

  • Executing a DOS Command from JSP

    How do i execute a Dos command from within JSP. I would like to execute a sql Loader command .
    Thanks

    You use Runtime.execute().
    Take a look here for a few of the tricks involved in it:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Executing shell commands from Java.

    I want to execute shell commands in Java using the Runtime.exec( String ) method.
    The method works fine under Linux OS, but under Windows '98 the method didn't work at all!
    For example the following call: Runtime.exec( "dir" ) throws an exception showing that the command was not completed. If I replace dir with ls under Linux all is good. What is the problem with the Microsoft Windows '98 ? Is there any solution at my problem ?!
    thx in advance!

    hey JSarmis,
    You can help me... "ls" doesn't work for me on linux.. using Runtime.exec, some commands work, others don't... you may hold the key to what i need? How did u get "ls" to work?

  • Invoking a UNIX shell command from Java stored procedure

    The program below is suppose do send an email using UNIX mailx program. It works correctly when I compile it in UNIX and invoke it from the command line by sending an email to the given address.
    I need this program to run as a stored procedure, however. I deploy it as such and try to invoke it. It prints the results correctly to the standard output. It does not send any emails, however. One other difference in execution is that when invoked from the command line, the program takes about a minute to return. When invoked as a stored procedure in PL/SQL program or SQL*Plus anonymous block, it returns immediately.
    Why would mailx invocation not work from a stored procedure? Are there other ways to invoke mailx from PL/SQL?
    Thank you.
    Michael
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.OutputStreamWriter;
    public class MailUtility
    public static void main(String[] args)
    System.out.println(mailx("Hey, there", "Hello", "oracle@solaris10ora", 1));
    * Sends a message using UNIX mailx command.
    * @param message message contents
    * @param subject message subject
    * @param addressee message addressee
    * @param display if greater than 0, display the command
    * @return OS process return code
    public static int mailx(String message, String subject,
    String addressee, int display)
    System.out.println("In mailx()");
    try
    String command =
    "echo \"" + message + "\" | mailx -r [email protected]" + " -s \"" + subject + "\" " + addressee;
    if (display > 0)
    System.out.println(command);
    try
    Process process = Runtime.getRuntime().exec("/bin/bash");
    BufferedWriter outCommand =
    new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
    outCommand.write(command, 0, command.length());
    outCommand.newLine();
    outCommand.write("exit", 0, 4);
    outCommand.newLine();
    outCommand.flush();
    process.waitFor();
    outCommand.close();
    return process.exitValue();
    catch (IOException e)
    e.printStackTrace();
    return -1;
    catch (Exception e)
    e.printStackTrace();
    return -1;

    try adding the full explicit path to "mailx" in the command string that gets sent to Runtime. i would guess that the shell that gets spawned might not have a proper environment and thus mailx might not be found.
    == sfisque

  • Invoking OS commands from JSP

    Hi!
    I am trying to invoke underlying Operating System's commands such as cd, or calling a batch file from my JSP.
    I achieve this by doing as below:
    String command = "cd temp";
    Process process = Runtime.getRuntim().exec(command);
    I need to know the current directory where this command would be invoked.
    How can I get the path? It's very urgent!
    Look forward to your response...
    Thanks in advance.....
    Sandesh

    actually, nevermind. that won't be the current directory. It will be this:
    String dir = System.getProperty("user.dir");

Maybe you are looking for

  • Opening a PDF in IE

    When I click on a hyperlink for a PDF in internet explorer, it get the usual, OPEN, SAVE or CANCEL, when I click OPEN, it launches another IE window before it open the PDF in Adobe Acrobat (Pro 8.1.2). On my old computer, this never happened, and I'd

  • Please Help me(SQL)

    I have a table named MEAL which contains a foreign key STU_NUM from STUDENT table so i want to insert two values into MEAL table using the criteria of STU_NUM. I have tried this code but it gives me Exception which says: Failed to insertjava.sql.SQLE

  • Problem in implementing ODATA update using SAP UI5

    Hi,   I am trying to develop an hwc mobile app [hwc] using sapui5 and phonegap. I am trying to perform odata crud operations in the app. In the netweaver side, currently we have disabled the setting for X-CSRF token so that CUD operations are possibl

  • Join between two nested tables question

    Hi. I have two nested tables with a join statement drawing info from both. The query looks like this: select to_char(N.LASTLOGONDATE, 'YYYY'), count(n.u_name), A.ACCOUNTDISABLED from coclastlogon, TABLE(COCLASTLOGON.RLLS) N , userpwaudit, TABLE(USERP

  • Prompted for updates I already have?

    Flash Player Version: 11.7.700.202 (persistent through several previous updates) OS: Windows 7, 64 bit Browser: Internet Explorer Often videos and ads will stops, replaced with a grey and white exclamation mark, and eventually a notice that I need to