Is it possible to execute .bat file located in package ?

Hi,
in my application i execute a print.bat file using Runtime.exec(), i'd like to place this .bat in package, let's say com.me.testpackage. How is it possible to execute the batch file from that location?
thanks

jschell wrote:
sabre150 wrote:
jschell wrote:
>Simple 'for' loops seem to work OK but still more research needed.
There is escaping in the for loops which is necessary in a bat file and not needed at the command line.
It seem to be that any command spanning more than one line fails. Fail? The example that gave shouldn't fail. It should simply run both echos.As I understand it, the command sequence
@echo off
goto XXX
echo out
:XXX
echo last
should just output 'last' and not 'out so if it prints both 'out' and 'last' then in my view it 'fails'. Am I missing something?
>
>>
Makes me even more pleased that I work mainly with Linux.Looking up syntax - what about getopts (bourne and korn)? You can also create 'functions', which can be defined later (if I recall correctly) in the script and called multiple times. I don't know how that would work streaming it in.I don't know about consequences of the streaming approach forward definitions in 'bourne' and 'korn' though I was not aware that 'bourne' allowed them. For 'bash' where forward definitions do not seem to be allowed (could I be mistaken in this?) then using        Process process = Runtime.getRuntime().exec("bash", null, new File(System.getProperty("user.home")));the following very simple 'bash' script (which contains loops, if statements and functions but no goto or forward definitions) can be executed without problems - # Simple bash script
function sayHello {
    echo "Hello" $1
sayHello "World" ;
for i in $( ls /tmp ); do
    echo file - $i
done
for i in `seq 1 10`;
do
    echo "seq" $i
done
i=0
while [  $i -lt 6 ]; do
if [ $i -eq 4 ]; then
    echo "then" $i
else
    echo "else" $i
fi
    let i=i+1
done
i=12
until [  $i -lt 10 ]; do
echo "until" $i
let i-=1
doneIn the past, I have also published examples of how to run Perl scripts using the same basic approach. The heart of the examples is         final String perlScript = "#!/bin/perl\n" +
            "print \"PID $$\\n\";\n" +
            "print \"UID $<\\n\";\n" +
            "print \"EUID $>\\n\";\n" +
            "print \"GID $(\\n\";\n" +
            "print \"\\nProcessing the command line arguments\\n\";\n" +
            "foreach (@ARGV) {\n" +
            "    $n = factorial($_);\n" +
            "    print \"    $_! = $n\\n\";\n" +
            "}\n" +
            "print \"\\n\".'@INC'.\"\\n\";\n" +
            "foreach (@INC) {\n" +
            "    print \"    $_\\n\";\n" +
            "}\n" +
            "print \"\\n\".'%ENV'.\"\\n\";\n" +
            "foreach (keys %ENV) {\n" +
            "    print \"    $_==$ENV{$_}\\n\";\n" +
            "}\n" +
            "$x = theAnswerToTheUltimateQuestion();\n" +
            "print \"\\nThe answer to the ultimate question is ... '$x'\\n\";\n" +
            "sub theAnswerToTheUltimateQuestion()\n" +
            "{\n" +
            "    return 3*2*7;\n" +
            "}\n" +
            "sub factorial()\n" +
            "{\n" +
            "    my ($n) = @_;\n" +
            "    return ($n > 1) ? $n * factorial($n-1) : 1;\n" +
            "}\n";
        System.out.println(perlScript);
         * The perl source can be from any InputStream. Here I use a
         * ByteArrayInputStream just as a demonstration.
        final InputStream perlSource = new ByteArrayInputStream(perlScript.getBytes());
         * The '-' indicates that the Perl script comes from stdin. The "a","b","c" etc
         * are the command line arguments passed to the Perl script.
        final String[] command =
            "perl", "-", "5", "6", "7", "8", "9", "10"
        final Process process = Runtime.getRuntime().exec(command);piping the 'perlSource' stream to the process stdin.
This runs as expected on both Linux (FC9 and Ubuntu 8.04) and on Windows using Active Perl.
Please don't take my use of a String to hold the Perl script to mean that I in any way endorse this approach - I just wanted a simple means to create a self-contained example.
>
And the c shell has a goto also.One day I might find some time and investigate 'c' shell goto in this context - since I have not used csh for at least 8 years I am very rusty.
I can't say that the 'streaming' approach will work with all Linux shells but I can say that on Linux I have had no problem with Perl and Bash. If anyone needs to use the 'streaming' approach with another shell then it takes just a few minutes to setup a test harness. If any problems are found then people can always resort to the 'Plan B' approach.
I am still pleased I work mainly with Linux and Unix.

Similar Messages

  • Executing *.bat file from PL/SQL

    Is there anyway for Executing *.bat file from PL/SQL ?
    Thanks

    Try here:
    asktom.oracle.com/pls/ask/f?p=4950:8:15427268967155079552::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:952229840241

  • Executing bat files from another location

    Hi
    In my application i need to execute a bat file which is in another location.
    i have my class file in c:\ds and i want to execute the bat file in c:\ds\src\jython.
    This is the code i have used
    private void executeBootstrapBat(){
    String cmd=null;
    cmd="cmd /c bootstrap C:\\DS\\HelperApplication\\src\\conf\\wsadmin-local.properties" +
    " " + getXmlFileName() + " " + getVOB();
    Runtime rt = Runtime.getRuntime();
    try{
    Process pt = rt.exec(cmd);
    }catch(IOException e){
    e.printStackTrace();
    }

    You can execute the bat file in any location. Butyou
    have to set the classpath in that location whereyou
    are executing the bat file.Please stop giving advice on this site. You do not
    have any clue what you are talking about at all.Actually I just went looked at a few more of your posts. All complete rubbish. Again please stop posting replies on this site until you get some clue about anything. It is very wrong of you to post replies like you know what you are doing and misleading those who don't know any better.

  • Need to execute bat file by GPO with admin rights

    Hi all
    I created a specific bat file that run regini.exe with specific parameters to set a specific permission in a specific registry key.
    I can execute this bat file from GPO but I need that this bat runs with domain admins rights otherwise script not set the permission in user's registry key.
    Have you any ideas?
    Thanks
    Chris

    > Yes I tested this solution but it's not possible set permission to the
    > key :-(
    Which key are we talking about?
    Martin
    Mal ein
    GUTES Buch über GPOs lesen?
    NO THEY ARE NOT EVIL, if you know what you are doing:
    Good or bad GPOs?
    And if IT bothers me - coke bottle design refreshment :))

  • How to execute .bat file within pl/sql block

    Hi,
    I want to execute a batch file (.bat) file withing a pl/sql procedure. Please guide me for it.
    Regards

    There are several possible ways to make a call-out from a PL/SQL program to the OS on the database server (but not to the client computer).
    You could use java or an external procedure (you'll need to code it in C) for example.
    You might be able to make use of UTL_HTTP to talk HTTP to another server or UTL_TCP to talk TCP to another server.
    What is it you are trying to do?

  • Error : How to execute *.BAT file

    Some of the friend said me to execute any file following code
    Runtime rt=Runtime.getRuntime();
    Process pr=null;
    pr = rt.exec("cmd.exe /c start " + "myfilename");
    I get error as
    CreateProcess: cmd.exe /c start myfilename error=0
    Press any key to continue . . .
    what is cmd.exe /c start in exec().
    Thanks..

    hi Bhavin
    try this code because i had the same problem an d this thing works for me here is the code
        // Get file name
        String File_Name = // What ever yr file name get as String
        // Get Operating System Name
        String os_name = System.getProperty("os.name");
        os_name = os_name.toUpperCase();
        // Declare command as array of string
        String[] command ;
        // on Windows XP, NT, 2000 command is different and on win 98, 95 is different
        if(os_name.indexOf("XP") != -1){
             command = new String[] {"cmd", "/C", "start", "\"\"", File_Name};
        else if(os_name.indexOf("NT") != -1){
             command =new String[] {"cmd", "/C", "start", "\"\"", File_Name};
        else if(os_name.indexOf("2000") != -1){
             command = new String[] {"cmd", "/C", "start", "\"\"", File_Name};
        else  {
             command = new String[] {"start", "\"\"", File_Name};
        try
            // Run the commands using Runtime
            Process process = Runtime.getRuntime().exec(command);
        catch(IOException ioe)
            //show Error message
                  JOptionPane.showMessageDialog((Component) null,
                                          "Unable to Locate the file..."+
                                          "\n"+ioe.getMessage(),
                                          "Error...",
                                          JOptionPane.ERROR_MESSAGE);
        }Regards
    Satinderjit

  • Hiding the command prompt when executing bat file

    Hi,
    I hava a bat file which contains following
    java -jar MyJar.jar
    When I execute the bat file, the jar file is executed. But a command prompt also opens along with it. I dont want to display the command prompt to the user. Is there any way to hide that command prompt ?
    regards,
    Jatin.

    Is your problem solved?
    If not then
    insted of creating a batch file create a form file in visual basic and write following code in it
    shell "java -jar MyJar.jar"
    Endand then create its exe file.
    It will just launch your jar file and then exit.

  • Execute bat file with cfexecute

    Hello,
    this is a newbie question but I'm stuck. I have a .bat that
    runs fine through the command prompt but won't run with
    <cfexecute>, it merely seems to read the .bat but not execute
    it. The .bat reads:
    java -classpath
    ".;C:\CFusionMX7\wwwroot\i-recall\javaClasses\GATE-3.1\bin\gate.jar"
    AnnieAPI
    When I run <cfexecute
    name="C:\CFusionMX7\wwwroot\i-recall\javaClasses\GateClasspathRun.bat"
    variable="myVar" timeout="100">
    </cfexecute>
    The output looks like this:
    C:\CFusionMX7\runtime\bin>java -classpath
    "C:\CFusionMX7\wwwroot\i-recall\javaClasses\GATE-3.1\bin\gate.jar"
    AnnieAPI
    It simply reads it and doesn't execute the java AnnieAPI
    command. I didn't write this .bat file so maybe I need to add
    something to make it run. Any help is appreciated.
    -Kalen G

    Same thing, just without the classpath in the output:
    C:\CFusionMX7\runtime\bin>java AnnieAPI
    Even if I remove the class path and simply leave java
    AnnieAPI it doesn't run. It should get an error message without the
    classpath or something but I don't And the page loads so quickly
    it's obvious that Coldfusion is just reading the code and not
    executing it.
    Thanks

  • Execute .bat file using cfexecute tag...

    Hello,
    I am trying to execute a batch file using cfexecute tag. This
    batch file needs 1 command line arguement, which I am passing using
    arguments
    Text attribute.
    When I run my batch file directly from command prompt, it
    works perfectly. but while using cfexecute, it doesn't seem to do
    anything.
    Note:- I am trying to encrypt a txt file using GPG algorithm
    in the batch file.
    Thanks in advance!
    Manju

    Hello,
    you have probally worked this out but if any of this helps :)
    I run an application that needs to print via dos command, so
    my cfm page makes a batch file writes some arguments to it then
    calls it with a cmd. the code is below if any of it helps im glad.
    (creates name for my bat file)
    <cfset BFname = '#namevariable#' & '.bat'>
    (sets up the text I need in the bat file)
    <cfset content = 'copy
    "c:\inetpub\wwwroot\mct\picklist.txt"
    \\MyPrintServer\ThePrinter'>
    (writes the bat file with the text in the content var)
    <cffile action="write"
    file="c:\inetpub\wwwroot\mct\#BFname#" output="#content#">
    (calls cmd to run the bat file)
    <cfexecute name="c:\windows\system32\cmd.exe"
    arguments="/c c:\inetpub\wwwroot\mct\#BFname#"
    outputfile="c:\inetpub\wwwroot\mct\log_output.txt"
    timeout="1"></cfexecute>
    Regards Guy

  • Problem executing .bat file from within Java class

    I'm stumped: I have no problem executing a .bat file that sets classpaths and executes a Java jar, but when I try to execute other executables first and then the .jar, my application hangs and since the DOS box doesn't come up over my GUI, I can't see what's going on.
    This works:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\omni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat 'omni.bat'
    set JAVA_HOME=c:\j2sdk1.4.2_04\bin
    %JAVA_HOME%\java -jar C:\CS47AUXS\OMNILOADJAR\OmniLoad.jar
    This doesn't work:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\jobomni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat file 'jobomni.bat'
    SET NETX_HOME=C:\CS47AUXS
    SET COBOL_HOME=C:\CS47AUXS\OFFLINE
    CD %NETX_HOME%
    CALL SET-NETX.CMD
    CD %COBOL_HOME%
    SSBPPC10 JOBOMNI X
    SET JH=C:\J2SDK1.4.2_04\BIN
    SET OMNI_HOME=C:\CS47AUXS\OMNILOADJAR
    CD %OMNI_HOME%
    %JH%\java -jar omniload.jar
    Can anyone shed some light here? Even when I execute the application from the command line the new DOS box doesn't become visible nor can I see any errors. If I could just get that visibility, I could probably figure out what is going wrong.

    Same problem with me as well.... Badly looking for a solution...
    I predict the following:
    - If your batch file has pretty less number of dos/shell commands then it gets executed fine with exec() and proc.waitFor();
    - If you increase the number of dos/shell commands in the bat file then try executing it then it definately hangs at proc.waitFor();
    Even "cmd.exe /C C:\\test.bat" hangs... if the commands are more...
    Is this some sort of bug? or am i doing anything wrong? I tried searching for solution on the net and search forums... but couldnt find a solution for the same.. not sure where i missed, what i missed...
    Incase some one finds a solution.. do post it here...
    Message was edited by:
    amadas

  • Executing bat file

    Hi..
    how can we execute a bat file in file..
    like batch file containg notepad .exe
    now executing the batch file from flex and notepad opens i want this
    thanks

    Well guys thanks for your response..
    i got an api named MERAPI that do this work..it has code written in java..and acts as a bridge between java and air
    http://www.merapiproject.net/index.php?option=com_content&view=article&id=47&Itemid=64&lim itstart=3
    now what i found here was that for executing the exe from flex it provides a function named systemExecute(array as parameter);
    I tried to implement this but was stuck somewhere with java..then got a help from the google groups..
    http://groups.google.com/group/merapi-project/browse_thread/thread/34db7ed7f0187b29?pli=1
    where the person saysin order to do this you have to run the bootstrap file..but how to do that
    Please help

  • Execute .Bat file from pl/sql code

    Hi,
    Can you please let me know that how can I execute the .Bat file from pl/sql procedure? Does anybody have a sample code??
    Thanks.

    Hi
    This may help you
    http://www.dba-oracle.com/t_running_windows_bat_file_dbms_scheduler.htm
    br,Jari

  • How to execute *.BAT file from  the Java Application

    Hello to all.
    I wants to run *.BAT file form my applicaion.
    Can u give the code of that two-four line,please
    Wating four your replay.
    Yours Friend
    Bhavin Shah.....

    pr = rt.exec("cmd.exe /c start " + yourProgramName)The exec() method executes the command you specify in the argument and returns a process. In this example, it's telling Windows to run "yourProgramName".
    HTH

  • How to execute .bat file through java?

    I already create a batch file to pull & push file. Now, i want to execute this .bat file java.I got this example but it doesnt work. Did i missed something or do we have the better one?
    import java.lang.*;
    import java.io.*;
    public class Loadfile
    public static void main(String args[]) throws IOException
    Runtime load = Runtime.getRuntime();
    r.exec("C:\\pull.bat");
    }

    For Runtime,i'd change it to:
    Runtime load = Runtime.getRuntime();
            String cmd = "C:\\javaclass\\copytemp.bat";
            Process proc = load.exec(cmd.toString());Is it right? But still can't work.
    Here is the .bat file:
    @echo off
    c:
    cd "c:\Inetpub\ftproot\Debitin"
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo open localhost
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo Administrator
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo password
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo cd ftpScript
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo binary
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo lcd C:\
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo lcd "C:\Inetpub\ftproot\infile"
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo prompt n
    pause
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo mget *.txt::@rem >> C:\Inetpub\ftproot\Logrecord\pullscript.txt echo mdel *.*
    C:\Inetpub\ftproot\Logrecord\pullscript.txt echo byeftp.exe -s:C:\Inetpub\ftproot\Logrecord\pullscript.txt
    ::del C:\Inetpub\ftproot\Logrecord\pullscript.txt
    pause
    exit
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Executing bat file without using Runtime.exec()??

    Hi all
    From my java App ,I am running a bat file. This is what I did:
    When I press 'execute' button inside my App, it runs a bat file through Runtime.exec() method. Since exec() runs it through cmd.exe, get a DOS window when I press Execute button. If I manually runs my app from command promt , I dont get it. But I have to create a short cut of my main class in the desktop. This is happening when I run my app from desktop icon.
    Now I want to eleminate DOS popup everytime I press execute button. Would anyone pls give an idea how to run bat file without using Runtime.exec()? Any suggestion will be helpful.
    Thanks

    jscell
    Thanks for taking time to answer to my problem .
    Here is what my problem: I create a shortcut of my main class in the desktop. Through this shortcut ,I run my java App. My App has a execute button, When I press this button , It run another bat file through Runtime.exec() method, and show some result in the result PAnel. NOw what happen , I get a DOS command window , everytime I press execute button. , Which is very annoying . But If I run my App thorugh command promt by executing: "java myApp", then I dont get this DOS popup. But I have to create a shortcut in the desktop, so other can use it conveniently.
    NOw I am not sure why I am getting this DOS window in the middle of my Application. IS it for using Runtime.exec() method? or for running bat file through my application? Can anyone pls tell me? I am kind of new to java, and I am learning lot of stuff from this forum .
    Would u pls suggest me about how to eleminate this DOS popup when I press execute button.
    Regrds

Maybe you are looking for

  • HELP! FOR LOOP TO SCROLL THROUGH TABLE AND CREATE DATABASE LINK

    Hi, Here's the scenario, not much of a PL programmer, just basic SQL so really need some help people! I have 2 tables. 1 contains list of DB's and the other contains rules to follow. I need to create a loop that goes through the table containing the

  • What's the best way to deal with floating point errors?

    What's the best way to deal with the decimal number errors in Flex? Lets say I have: var number1:Number = 1.1; var number2:Number = 1; var result:Number = number1 - number2; trace(result); I get "0.10000000000000009". What's the best way to deal with

  • Issue with macbook pro Hi-res antiglare purchace

    So the story goes that I went to buy a 15 inch mb pro from the apple store in indianapolis in. I walked in with cash, and walked out with nothing. I bought and returned 3 macbook pro's in a row due to slight problems with the screen. All three macboo

  • Macbook freezes up with a black box in the middle of the screen.

    My Macbook freezes up with a black box in the middle of the screen. Inside the black box is a message to power down and then re power up. The Mac does re-start, but freezes up again after a while. Does anybody know how to get rid of this problem?

  • Hard drive access locked to all users

    I have a second internal HD on my Power Mac G5 that is locked to all users. I have tried many different things and have been unable to make it available to myself. I could just format the drive but there is valuable work data on there. Any help would