Runtime to string

Runtime r = Runtime.getRuntime();
r.exec("cmd /c mem");
(Thankyou meadandale, of whom I found this from off an old post.)
I need to be able to manipulate the text returned from any DOS command executed in this way (send to system.out, filewriter, whatever). I would assume I need to convert it to a String class, but how? I've been searching around, and cant find anything on it.

Take a look at this article from JavaWorld, it's pretty definitive:
When Runtime.exec() won't
Navigate yourself around pitfalls related to the Runtime.exec() method
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Similar Messages

  • PB with Runtime.exec(String);

    hi,
    in using Runtime.exec(string);
    he say :
    the method exec(java.lang.String) from the type java.long.Runtime is not static.
    Someone can help me please.

    use:
    Runtime.getRuntime().exec(String);

  • Parameter  to shell script using Runtime.exec(string)

    Hi all, ( Speciall hi to dheeraj tak )
    Briefly : How do i pass an arguement to a non - java executible being called using Runtime.exec.
    In detail : i am using Runtime.exec to call a shell script : The code is as follows:
    String callAndArgs[] = {"/home/tom/jakarta-tomcat-4.1.24/webapps/dash/script.sh"};
    try {
    Runtime rt = Runtime.getRuntime();
    Process child = rt.exec(callAndArgs);
    This works properly & calls the shell script which in turn invokes some other executible (c file).
    $HOME/midi/test/build/bin/<C-EXECUTIBLE>
    Here i am specifying the name (say hello.exe ) . So far so good.
    I want to make this happen dynamiclaly. so i need to pass the name of the executible as a parameter to the script.
    To pass a parameter i hav to change the string to :-
    String callAndArgs[] = {"/home/tom/jakarta-tomcat-4.1.24/webapps/dash/script.sh <C-EXECUTIBLE HERE>"};
    and the script to
    $HOME/midi/test/build/bin/$1 --- where $1 refers to argument 1. (C-EXECUTIBLE AGAIN).
    This is giving an IO - Execption. Plz help
    Code will be very helpful.
    Thanx in advance

    some 1 plz tell me the difference :-
    This is the documentation of Runtime.exec that i found :-
    1> exec
    public Process exec(String command) throws IOException
    Executes the specified string command in a separate process.
    The command argument is parsed into tokens and then executed as a command in a separate process. This method has exactly the same effect as exec(command, null).
    Parameters:
    command - a specified system command
    Complete refernce says : Process (String progName) ----- Executes a program specified by programname as a seperate process.
    2> exec
    public Process exec(String cmdarray[]) throws IOException
    Executes the specified command and arguments in a separate process.
    The command specified by the tokens in cmdarray is executed as a command in a separate process. This has exactly the same effect as exec(cmdarray, null).
    Parameters:
    cmdarray - array containing the command to call and its arguments.
    Complete reference says : Process exec(String comLineArray[]) ---- Executes the command line specified bythe string in comLineArray as a seperate process.
    This means that there is provision 4 command line arguments...
    how do u use it then????????????????????????????

  • UNIX Problem with method Runtime exec(String[],String[],File)

    Hello !!
    i'm french
    scuse my english
    I got a probleme with method exec(String[],String[],File) of Runtime Class
    i don't have any probleme when my program runs on Windows NT but the same program on UNIX doesnt execute my command..
    When i use exec(String[]) methode i dont have this problem ...but i need the second one methode because i have to execute my command in a different directory than the JAVA program.
    I need that results of this command are placed in this drectory so that i can't use an exex() like that :
    exemple with a perl :
    "perl /toto/titi/hello.pl"
    I want to execute this :
    "perl hello.pl" (and hello.pl is placed in /toto/titi)
    Conclusion :
    the exec(String[],String[],File) solution is ok with NT ...
    but with UNIX ????
    Is there other solution ??
    Should i do a "cd" command before my execution ? how can i do this ??
    Thanks !!!!

    Could you post your source code (only relevant part)
    Raghu

  • Problem  in  executing dos command from runtime.exec(String command);

    Hi
    i have wriiten a code for running command of DOS-Promt
    try
         rnt1 = Runtime.getRuntime();
                                  proc1= rnt1.exec("myb");//myb is a batch file      and proc1 is process class instance
                                                                try
                                  proc1.waitFor();
                                  catch (InterruptedException e)
                             System.out.println("InterruptedException raised: "+e.getMessage());
                   catch (IOException ioe)
              System.out.println("IOException raised: "+ioe.getMessage());
    But it is giving error while running:
    this is showing as an IO exception
    CreateProcess: myb error=0
    Please help me how to proceed
    Thanks

    There are 2 possible reasons (perhaps concurrent):
    1. The file to be executed is not in the same path of your application, and you MUST specify its whole absolute path as exec() argument;
    2. The file to be execute is really (as you call it) a DOS batch file, and then it HAS TO BE NAMED (and called) myb.BAT or (under NT/2000) myb.CMD; WinDOS is Not Unix (WNU): extensions rule!!!

  • Runtime.exec with spaces not working EVEN using String[]!!

    Hi everyone,
    I need to start the rmi registry from some code,and i need to pass it the classpath of two jars when initialising it. My problem is that the paths I set aren't taken when they contain a space.
    Here's the code:
    <code>
    String rmiRegistryCommandLine[] = new String[] {
    + System.getProperty("java.home")
    + "\\bin\\rmiregistry.exe\"",
    "-J-Djava.class.path=\""+System.getProperty("user.dir")+"\\MyJar.jar\"",
    "1099"};
                                            Runtime.getRuntime().exec(rmiRegistryCommandLine);
    </code>
    I know that Runtime.exec(String) tokenizes the input, which is why I'm not using it, but Runtime.exec(String[]) isn't supposed to tokenize the input. System.getProperty("user.dir") can contain a space, so I put quotes around that, but I need the -J-Djava.class.path in the same string. I tried breaking it up into two more separate strings but it didn't even run for normal non-space paths then. I am sure that if the whole -J-Dblah....upto MyJar.jar was in quotes then it would work, but I need the classpath in quotes separately as it could contain a space.
    Can anyone help me get this working?

    Ya, that's fine but the command line I want to pass is:
    d:\j2sdk1.4.0\bin\rmiregistry.exe -J-Djava.class.path=d:\my dir with spaces\MyJar.jar;d:\my more dir with spaces\MyJar2.jar 1099
    If I say
    arg[0]="d:\\j2sdk1.4.0\\bin\rmiregistry.exe";, that's finebut arg[1] is the problem
    if I say
    arg[1]="-J-Djava.class.path=d:\\my dir with spaces\MyJar.jar; d:\\my more dir with spaces\\MyJar2.jar";, then it definitely won't work on 9X machines and probably not on NT.
    if I break up arg[1] into:
    arg[1]="-J-Djava.class.path=";
    arg[2]="d:\\my dir with spaces\\MyJar.jar";
    arg[3]=";";
    arg[4]="d:\\my more dir with spaces\\MyJar2.jar";I'll need to put quotes around the two individual two class paths or else it won't work.
    I find though that if I put the classpath as follows
    d:\"my dir with spaces"\MyJar.jar then it seems to work.
    I think a regular expression function to search for any directory with spacees and then put quotes around it and reinsert it into the path would be the solution.

  • How to execute an application in Solaris using Runtime.getRuntime.exec() ?

    I am currently doing a project which requires the execution of Solaris applications through the use of Java Servlet with this Runtime method - Runtime.getRuntime.exec()
    This means that if the client PC tries to access the servlet in the server PC, an application is supposed to be executed and launched on the server PC itself. Actually, the servlet part is not an issue as the main problem is the executing of applications in different platforms which is a big headache.
    When I tried running this program on a Windows 2000 machine, it works perfectly fine. However, when I tried it on a Solaris machine, nothing happens. And I mean nothing... no errors, no nothing. I really don't know what's wrong.
    Here's the code.
    public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
         response.setContentType("text/html");
         PrintWriter out = response.getWriter();
              Process process;                                                       Runtime runtime = Runtime.getRuntime();
              String com= "sh /opt/home/acrobat/";
              String program = request.getParameter("program");
              try
                        process = runtime.exec(com);
              catch (Exception e)
                   out.println(e);
    It works under Windows when com = "c:\winnt\system32\notepad.exe"
    When under Solaris, I have tried everything possible. For example, the launching of the application acrobat.
    com = "/opt/home/acrobat"
    com = "sh /opt/home/acrobat"I have also tried reading in the process and then printing it out. It doesn't work either. It only works when excuting commands like 'ls'
    BufferedReader read = new BufferedReader(new InputStreamReader(process.getInputStream()));Why is it such a breeze to execute prgrams under Windows while there are so many problems under Solaris.
    Can some experts please please PLEASE point out the errors and give me some advice and help to make this program work under Solaris! Please... I really need to do this!!
    My email address - [email protected]
    I appreciate it.
    By the way, I'm coding and compiling in a Windows 2000 machine before ftp'ing the .class file to the Solaris server machine to run.

    it is possible that you are trying to run a program that is going to display a window on an X server, but you have not specified a display. You specifiy a display by setting the DISPLAY environment variable eg.
    setenv DISPLAY 10.0.0.1:0
    To check that runtime.exec is working you should try to run a program that does not reqire access to an X Server. Try something like
    cmd = "sh -c 'ls -l > ~/testlist.lst'";
    alternatively try this
    cmd = "sh -c 'export DISPLAY=127.0.0.1:0;xterm '"
    you will also need to permit access to the X server using the xhost + command

  • Why is Runtime.getRuntime().exec() not working in JSP?

    Hi all,
    I need to execute a command file from a JSP. I am using Tomcat 4.0.3.
    Here is the code :
    I just wanted to test if this will work, so tried to do run notepad.exe. But in my actual project, i need to run some other commands from a bat file or cmd file.
    <%@ page import="java.util.*,java.io.*,java.net.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="tryexec" %>
    //tryexec is a class which has the same java statements as in this jsp
    <%     
    Runtime r = Runtime.getRuntime();
    String s3 = "C:\\WINNT\\explorer.exe";
    String s4 = "C:\\bin\\open.cmd"; //inside open.cmd file , i have "notepad.exe"
    r.exec(s3);
    r.exec(s4);
    /*     tryexec c = new tryexec();
         c.execTo(); // doesn't work
    %>
    I have a html page , when i click a button there , it will call the above jsp , and this jsp will execute the command file.
    If i run the above java statements using a simple java program, it works fine, it opens a notepad and explorer window. but if i do the same thing in jsp, why doesn't it work? Is there any security problem? no exception is shown . Is it a problem with tomcat?
    I also tried to import the java class in jsp and call the function, but still didnt work.
    Please let me know whats the problem, and how to execute command files from jsp.
    Thanks
    Priyha

    It would work with Java coz u r working on the same machine as the java class file.
    While in case of JSP, it is like connecting to a different machine (even if the server is running on the same machine). If you do something like "net send user message" command in JSP or something other executable (just to test), you would see it to work.
    I hope you understand my point here.
    Write back if you have any issues.
    Regards
    Aruneesh

  • Monitoring a Process using Runtime.exce()

    Hi,
    In my Program, I'm using the
    new BufferedReader(new InputStreamReader(Runtime.getRuntime()                         .exec("ps -ef | grep xmlfeed").getInputStream()));
    The above statement is not returning any inputstream to the BuffredReader.
    When I gave the command as "PWD", it's returning the lines as expected.
    But it's not working even for "PS" command also.I'm running this in AIX machine.
    Any Ideas,Please help....
    Edited by: haijdp on Dec 21, 2007 1:11 AM

    Hello! And sorry I didn't reply earlier. I hope the Original Poster will find revisit this thread and it helps him.
    From your post I assumed that you were not a student trying to create some homework. That's why I felt free to simply code a solution and submit the code here. But first some remarks:
    I don't think that your code can work. Runtime.exec expects an array of type String, where the first element is the command and subsequent elements are a command line option each. I don't think you can use the pipe and call several commands using Runtime.exec, but that's just a kind of guess. YMMV.
    Running external Processes in Java is a bit complicated. Basically,
    * It's good to run the process in it's own thread. That way the main program can continue without getting stuck.
    * To extract stdout and stderr of your target process you must run two threads, one for stderr and one for stdout. Both threads extract the characters of their respective streams in a loop that runs inside the thread. Again, that way we avoid deadlocks, program getting stuck etc.
    This explanation is terrible, I know - I think a slice of source code speaks louder than words. I have attached five java files which together make a little process runner which extracts stdout and stderr in a safe manner. To run:
    * Cut'n paste them into five text files, one per class.
    * Save the each text file as {contained-class-name}.java
    * Compile the stuff
    * Run RunnerDemo (When I ran it, I got a directory listing printed on the console)
    Explanation sounds a bit sloppy, but I did it under the assumption that you are a seasoned java pro, so it should not pose any problems. Since you seem to be a different OS than I (AIX, I run Linux), the command may or may not work. Try other commands. For example, in the RunnerDemo class you could set the cmd field to this:
            String [] cmd =
                "ps",
                "-A",
                "-H"
            };This would give you a process listing (works on Linux).
    By the way, commands are passed as array. See Java documentation for java.lang.Runtime.exec (String []) for explanation of this array.
    One problem I see in your command is that the output of ps is piped to some other program. Sorry, I don't know whether my code could achieve this. All it can do is to rum one single command with command line options. But you should be able to adjust the given example, so it supports piping to another program.
    If you have any further questions, please don't hesitate to ask!
    Class: RunnerDemo
    *                           RunnerDemo.java
    *                     Demo for the process runner
    package rtimeexec;
    public class RunnerDemo
        public static void main (String [] args)
            String [] cmd =
                "ls",
                "-a",
                "-l"
            ProcessRunner   runner;
            String          stdOutStr;
            String          stdErrStr;
            runner = new ProcessRunner (cmd);
            runner.start ();
            runner.BlockUntilFinished ();
            stdOutStr = runner.GetStdOutText ();
            stdErrStr = runner.GetStdErrText ();
            System.out.println ("Process result, ls -a -l");
            System.out.println ("-----------------------------------------------------------------------");
            System.out.println ("Stdout:");
            System.out.println ("-----------------------------------------------------------------------");
            System.out.println (stdOutStr);
            System.out.println ();
            System.out.println ("-----------------------------------------------------------------------");
            System.out.println ("Stderr:");
            System.out.println ("-----------------------------------------------------------------------");
            System.out.println (stdErrStr);
    Class: ProcessRunner
    package rtimeexec;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    * Runs a system process and extracts stdout and stderr of that process.
    * Process will run in its own thread, so that the caller can simply continue
    * with less of a chance to get locked down. Caller can invoke the {@link BlockUntilFinished}
    * method after starting this thread. This method blocks until the thread is finished,
    * i.e. the process has finished.
    * Unfortunately, we haven't implemented any facility to stream characters to
    * stdin of the process called. If that facility would exist we could refactor
    * the classes and realize some sort of piping facility, as it's possible in
    * Linux, for example.
    * Example on how to run a process:
    * <pre>
    * String []         cmd  = {"ps", "-AH"};
    * String            sOut;
    * String            sErr;
    * ProcessRunner     runner;
    * runner = new ProcessRunner (cmd);
    * runner.start ();
    * runner.BlockUntilFinished ();
    * sOut = runner.GetStdOutText ();
    * sErr = runner.GetStdErrText ();
    * System.out.println ("Stdout:");
    * System.out.println (sOut);
    * System.out.println ("------------------------------------------------------");
    * System.out.println ("Stderr:");
    * System.out.println (sErr);
    * </pre>
    public class ProcessRunner extends Thread
        private String []                   command;
        private int                         execResult;
        private String                      stdOutText;
        private String                      stdErrText;
        private boolean                     isFinished;
        public ProcessRunner (String [] cmd)
            command     = cmd;
            execResult  = 0;
            stdOutText  = null;
            stdErrText  = null;
            isFinished  = false;
        public int GetResult ()
            return execResult;
        public String GetStdOutText ()
            return stdOutText;
        public String GetStdErrText ()
            return stdErrText;
        public boolean IsFinished ()
            return isFinished;
        public void BlockUntilFinished ()
            while (! isFinished)
                try {Thread.sleep (250);} catch (InterruptedException e) {}
        public void run ()
            Process         proc;
            Runtime         rt;
            InputStream     stdOut;
            InputStream     stdErr;
            CharStream      stdOutEx;
            CharStream      stdErrEx;
            int             res;
            isFinished = false;
            try
                res         = 0;
                rt          = Runtime.getRuntime ;       ();
                proc        = rt.exec ;                  (command);
                stdOut      = proc.getInputStream ;      ();
                stdErr      = proc.getErrorStream ;      ();
                stdOutEx    = new CharStream            (stdOut);
                stdErrEx    = new CharStream            (stdErr);
                stdOutEx.start ();
                stdErrEx.start ();
                try {res = proc.waitFor ();} catch (InterruptedException e) {}
                // Process has finished; now wait until any buffers are empty.
                stdOutEx.BlockUntilFinished ();
                stdErrEx.BlockUntilFinished ();
                stdOutText = stdOutEx.GetResult ();
                stdErrText = stdErrEx.GetResult ();
                execResult = res;
            catch (IOException e)
                isFinished = true;
                throw new ExtractionException (e.getLocalizedMessage());
            isFinished = true;
    Class: CharStream
    package rtimeexec;
    import java.io.IOException;
    import java.io.InputStream;
    * A Character extractor. Extracts characters from a stream and puts them
    * into a String. To protect from memory overflow we put a limit in place.
    * When storage demads exceed that limit, an exception is thrown.
    public class CharStream extends Thread
        private static final int    maxChunkLen         = 8192;
        private static final int    maxStorageSize      = 512 * 1024;   // 512 KBytes
        private InputStream     sourceStream;
        private StringBuffer    extracted;
        private boolean         isFinished;
        public CharStream (InputStream istream)
            sourceStream    = istream;
            extracted       = new StringBuffer ();
            isFinished      = false;
        public String GetResult ()
            String ret;
            ret = extracted.toString ();
            return ret;
        public void BlockUntilFinished ()
            while (! isFinished)
                SleepThread (250);
        public void run ()
            byte []                 buffer;
            int                     nBytesRead;
            byte                    b;
            char                    c;
            int                     iChar;
            int                     nCharsTotal;
            boolean                 isEOF;
            isEOF       = false;
            nCharsTotal = 0;
            isFinished = false;
            while (! isEOF)
                try
                    buffer      = new byte [maxChunkLen];
                    nBytesRead  = sourceStream.read (buffer);
                    if (nBytesRead >= 1)
                    {   // much faster stream extraction method than when we use
                        // BufferedReader(new InputStreamReader(sourceStream)).
                        for (iChar = 0; iChar < nBytesRead; iChar++)
                            nCharsTotal++;
                            if (nCharsTotal > maxStorageSize)
                                throw new StoreFullException
                                    "Storage limit exceeded (" + Integer.toString (maxChunkLen) + "Bytes)"
                            b = buffer [iChar];
                            c = (char) b;
                            extracted.append (c);
                    else if (nBytesRead <= -1)
                        isEOF       = true;
                catch (IOException e)
                    isFinished = true;
                    throw new ExtractionException (e.getLocalizedMessage());
                SleepThread (250);
            isFinished  = true;
        private void SleepThread (int mSec)
            try
                Thread.sleep (mSec);
            catch (InterruptedException e)
    Class: StoreFullException
    package rtimeexec;
    * Exception that gets thrown when a storage container is full.
    public class StoreFullException extends RuntimeException
        private static final long serialVersionUID = - 4996246591135389009L;
        public StoreFullException (String message)
            super (message);
    Class: ExtractionException
    package rtimeexec;
    * Thrown when there was some problem during stream extraction.
    public class ExtractionException extends RuntimeException
        private static final long serialVersionUID = - 6124525536783450209L;
        public ExtractionException (String message)
            super (message);
    }

  • FTP using Runtime class ...Please Help ??

    Hi,
    I am trying to ftp a file programatically.
    I am trying to use Runtime class but facing problems
    in it.This is what I am trying to do :
    Runtime rr = Runtime.getRuntime();
    String[] cmds = new String[2];
    cmds[0]="username=rahmed";
    cmds[1]="password=prpas";
    try{
    Process p = rr.exec("ftp 192.168.1.18",cmds);     
    rr.exec("put vv.txt");
    This does not work ??
    Is there any way to make it work ? Or is there any
    other way to ftp a file programatically ??
    Thanks in adavance..
    Regards
    Rais

    Under Linux/Unix at least, it is good to use the switches -n and -i with the ftp client acually meant for intercative usage.
    -i Turns off interactive prompting during multiple file transfers.
    -n Restrains ftp from attempting ``auto-login'' upon initial connection.
    I do "user <myuser> <mypassword>" then from the script.
    I am happily using ftp this way from shell-scripts in my projects.
    scp is however better than ftp: it does not send plain text passwords over the net, it support key-based login, its encrypts the data.

  • Executing a shell script from java using runtime.exec()

    Hi I am trying to create a script (test_script) and execute it -- all within one java program...
    the code compiles and executes perfectly but nothing happens. This is probably because the script does not get changed to the '777' mode although i am trying to do that ... any suggestions ???
    //code
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
         public ScriptBuilder() {
         public void writeScript() throws java.io.IOException{
         FileWriter writer = new FileWriter(new File("test_script"));
              writer.write("#! /bin/sh\n");
              writer.write("cd prodiags\n");
              writer.write("tar cvf delTask.tar delTask\n");
              writer.write("rm -rf delTask\n");          
              writer.flush();
              writer.close();
    Runtime rt= Runtime.getRuntime();
    String[] cmd = new String[3];
    cmd[0] = "ls";
    cmd[1] = "chmod 777 test_script";
    cmd[2] = "./test_script";
    rt.exec(cmd);
         public static void main (String[] args)throws java.io.IOException
         ScriptBuilder sb = new ScriptBuilder();
         sb.writeScript();
    }

    I don't know exactly but the code written below is working fine try the same with your code .Even with your code instead running the code with
    " ./<filename> ",if you execute it with "sh <filename>" command without changing the mode of the file it is executing properly.
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
    public ScriptBuilder()
    public void writeScript() throws java.io.IOException
    FileWriter writer = new FileWriter(new File("test_script"));
    writer.write("#! /bin/sh\n");
    writer.write("ll>/home/faiyaz/javaprac/checkll");
    writer.flush();
    writer.close();
    Runtime rt= Runtime.getRuntime();
    rt.exec("chmod 777 test_script");
    rt.exec("./test_script");
    } public static void main (String[] args)throws java.io.IOException
    ScriptBuilder sb = new ScriptBuilder();
    sb.writeScript();
    }

  • Changing Text property of TextObject at runtime has unexpected results

    I'm using the version of Crystal Reports that ships with VS 2008.
    At runtime, I'm replacing the text of a TextObject with new text. This works fine when the TextObject contains only literal information, but when the TextObject contains a formula field it does not work as expected.
    If I have the following in the designer:
    Text1 with text of "Number: {@FormulaX}"
    And in the runtime code (in the InitReport method):
    Text1.Text = "N.: {@FormulaX}"
    The observed output is: N.: {@ForumlaX}
    Instead of the expected output of: N.: 5
    I even tried the following in the runtime code:
    string foo = Text1.Text;
    Text1.Text = foo;
    And it produced similar results.
    Any ideas on what's going on, or how to get the results I'm expecting?

    The Text property doesn't interpret the formula syntax. You'll need to use a RAS TextObject to accomplish this.
    Note: This inproc RAS code will only work with Crystal Reports XI R2 SP2 and Crystal Reports 2008.
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.ReportAppServer.ClientDoc;
    using CrystalDecisions.ReportAppServer.DataDefModel;
    public partial class _Default : System.Web.UI.Page
        protected ReportDocument boReportDocument;
        protected void Page_Load(object sender, EventArgs e)
            if (!this.IsPostBack)
                ConfigureCrystalReports();
            CrystalReportViewer1.ReportSource = Session["Report"];
        protected void ConfigureCrystalReports()
            ISCDReportClientDocument boReportClientDocument;       
            CrystalDecisions.ReportAppServer.Controllers.ReportObjectController boReportObjectController;
            CrystalDecisions.ReportAppServer.ReportDefModel.TextObject boOldTextObject, boNewTextObject;
            CrystalDecisions.ReportAppServer.ReportDefModel.Paragraph boParagraph;
            CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphFieldElement boParagraphFieldElement;
            CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphTextElement boParagraphTextElement;
            boReportDocument = new ReportDocument();
            boReportDocument.Load(Server.MapPath("CrystalReport.rpt"));
            boReportClientDocument = boReportDocument.ReportClientDocument;       
            boReportObjectController = boReportClientDocument.ReportDefController.ReportObjectController;
            // Get a handle on the ReportObjectController so we can manipulate the TextObject       
            foreach (CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject boReportObject in boReportObjectController.GetAllReportObjects())
                if (boReportObject.Kind == CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindText)
                    boOldTextObject = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)boReportObject;
                    boNewTextObject = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)boOldTextObject.Clone(true);
                    // Clear out all paragraphs from the current text object
                    boNewTextObject.Paragraphs.RemoveAll();
                    // Create a new Paragraph to add to our TextObject
                    boParagraph = new CrystalDecisions.ReportAppServer.ReportDefModel.Paragraph();
                    // Create a new ParagraphTextElement to be added to our paragraph
                    boParagraphTextElement = new CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphTextElement();               
                    boParagraphTextElement.Text = "The value of my parameter is: ";
                    boParagraph.ParagraphElements.Add(boParagraphTextElement);               
                    // Create a new ParagraphFieldElement (our parameter field) to be added to our paragraph               
                    boParagraphFieldElement = new CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphFieldElement();
                    boParagraphFieldElement.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrParagraphElementKindEnum.crParagraphElementKindField;
                    boParagraphFieldElement.DataSource = "{?Currency}";               
                    boParagraph.ParagraphElements.Add(boParagraphFieldElement);
                    boNewTextObject.Paragraphs.Add(boParagraph);
                    boReportObjectController.Modify(boOldTextObject, boNewTextObject);
                    break;
            Session.Add("Report", boReportDocument);

  • Errors- Runtime() in Swing Help

    Hi, Iam trying to use Runtime() in Swing..iam getting nonsense errors what have i missed?
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class appSrunCommand extends JApplet implements Runnable,ActionListener{
         JLabel l1;
         JTextField tf;
         JButton run;
         JTextArea ta;
         JScrollPane jsp;
         String[] cmd = new String[4];
              public void init(){
                   l1 = new JLabel("Enter the command");
                   tf = new JTextField(10);
                   run = new JButton("Run");
                   ta = new JTextArea(20,20);
                   //jsp = getConentPane();
                   run.addActionListener(this);
                        Container con = getContentPane();
                        con.setLayout(new FlowLayout());
                        con.add(l1);con.add(tf);con.add(run);
                        con.add(ta);
                        public void actionPerformed(ActionEvent e){
                             String comm = tf.getText();
                             cmd[0]= "appSrunCommand";
                             cmd[1] = "cmd.exe";
                             cmd[2] = "/C";
                             cmd[3] = comm;
                             try{
                                  Runtime rn = Runtime.getRuntime();
                                  String temp = "";
                                  ta.setText(String.valueOf("Executing "+ cmd[0]+" "+cmd[1]+" "+cmd[2]+" "+cmd[3]));
                                  Process p = rn.exec(cmd);
                                  int exitVal = rn.waitFor();
                                  ta.setText(String.valueOf(exitVal));
                                  // any error message?
                StreamGobbler errorGobbler = new
                    StreamGobbler(rn.getErrorStream(), "ERROR");           
                // any output?
                StreamGobbler outputGobbler = new
                    StreamGobbler(rn.getInputStream(), "OUTPUT");
                // kick them off
                errorGobbler.start();
                outputGobbler.start();
                // any error???
                //int exitVal = rn.waitFor();
                             catch(Throwable t){
                                  ta.setText(String.valueOf(t));
    class StreamGobbler extends Thread{
                   InputStream is;
                   String type;
              //     Thread t = new Thread(this);
              //     t.start();
                        StreamGobbler(InputStream is,String type){
                             this.is = is;
                             this.type = type;
                                  public void run(){
                                       try{
                                            BufferedReader br = new BufferedReader( new InputStreamReader());
                                            String line = null;
                                            while((br.readLine())!= null)
                                            //ta.setText(String.valueOf(type+">"+ line));
                                            System.out.println(type+">"+line);
                                       catch(IOException ioe){}
                                       //     ta.setText(String.valueOf(ioe));
              Here are the errors..
    --------------------Configuration: <Default>--------------------
    C:\j2sdk\bin\appSrunCommand.java:11: appSrunCommand is not abstract and does not override abstract method run() in java.lang.Runnable
    public class appSrunCommand extends JApplet implements Runnable,ActionListener{
           ^
    C:\j2sdk\bin\appSrunCommand.java:45: cannot resolve symbol
    symbol  : method waitFor ()
    location: class java.lang.Runtime
                                                    int exitVal = rn.waitFor();
                                                                    ^
    C:\j2sdk\bin\appSrunCommand.java:49: cannot resolve symbol
    symbol  : method getErrorStream ()
    location: class java.lang.Runtime
                    StreamGobbler(rn.getErrorStream(), "ERROR");           
                                    ^
    C:\j2sdk\bin\appSrunCommand.java:53: cannot resolve symbol
    symbol  : method getInputStream ()
    location: class java.lang.Runtime
                    StreamGobbler(rn.getInputStream(), "OUTPUT");
                                    ^
    C:\j2sdk\bin\appSrunCommand.java:80: cannot resolve symbol
    symbol  : constructor InputStreamReader ()
    location: class java.io.InputStreamReader
                                                                    BufferedReader br = new BufferedReader( new InputStreamReader());
                                                                                                            ^
    5 errors
    Process completed.

    appSrunCommand is not abstract and does not override abstract method run() in java.lang.RunnableThis error message doesn't only tell you what's wrong, it also gives you hints about how to fix it. Why don't you read the messages?

  • How to capture output of java files using Runtime.exec

    Hi guys,
    I'm trying to capture output of java files using Runtime.exec but I don't know how. I keep receiving error message "java.lang.NoClassDefFoundError:" but I don't know how to :(
    import java.io.*;
    public class CmdExec {
      public CmdExec() {
      public static void main(String argv[]){
         try {
         String line;
         Runtime rt = Runtime.getRuntime();
         String[] cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E.java";
         Process proc = rt.exec(cmd);
         cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E";
         proc = rt.exec(cmd);
         //BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
         BufferedReader input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
         while ((line = input.readLine()) != null) {
            System.out.println(line);
         input.close();
        catch (Exception err) {
         err.printStackTrace();
    public class E {
        public static void main(String[] args) {
            System.out.println("hello world!!!!");
    }Please help :)

    Javapedia: Classpath
    How Classes are Found
    Setting the class path (Windows)
    Setting the class path (Solaris/Linux)
    Understanding the Java ClassLoader
    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

  • Substitute an apostrophe in a String class

    I've spent two days on this problem so I figure it's time to drop the "trial and error" and get an answer.
    I am building an employee directory on which a tooltip will display the
    employee's name and 3 phone numbers. The data will be formatted in
    the hovertext as a table, like so: tipContent =
      "<table>" +
        "<tr>" +
          "<td class=ToolTipTD colspan=2 >" + strName + "</td>" +
        "</tr>" +
        "<tr>" +
          "<td class=ToolTipTD>Work:</td>" +
          "<td class=ToolTipTD>" + strWorkph + "</td>" +
        "</tr>" +
        "<tr>" +
          "<td class=ToolTipTD>Cell:</td>" +
          "<td class=ToolTipTD>" + strCellph + "</td>" +
        "</tr>" +
        "<tr>" +
          "<td class=ToolTipTD>Home:</td>" +
          "<td class=ToolTipTD>" + strHomeph + "</td>" +
        "</tr>" +
      "</table> ";This works great, unless the employee's name in strName contains an
    apostrope (O'Brien).
    I had partial success in my first attempt using the replaceAll method:strName.replaceAll( "'" , " & # 3 9 " ) // w/o the xtra spacesThis worked on my test PC, but not on our production servlet
    container. On this system, the second parm of the replaceAll was
    converted to an apostrope before sending the string to my
    browser...causing it to fail.
    It was suggested that I swich to unicode, but I'm running into some of
    the same issues using " \ u 0 0 2 7 " instead of my original 2nd
    parameter.
    So my question is this...how can I convert this string (just looking at the first cell of the table:
    "<td class=ToolTipTD colspan=2 >O'Brien, Pat</td>"to this string?:"<td class=ToolTipTD colspan=2 >O\u0027Brien, Pat</td>"TIA.

    Thanks for getting me back on track. Just to confirm:
    Running Tomcat on my PC, at runtime, the string is translated to:<td class=ToolTipTD colspan=2 >O & # 3 9 Brien, Patl</td> // w/o xtra spacesBut in my production installation, the string looks like this at runtime:<td class=ToolTipTD colspan=2 >O'Brien, Pat</td>The production servlet container is IBM's HTTP Server for i5/OS (powered by Apache)...http://www-03.ibm.com/servers/eserver/iseries/software/http/.
    If this is a configuration problem, I should be able to change my local Tomcat configuration to produce the same "bad" results. Specifically, what configuration option(s) would do this? TIA.

Maybe you are looking for

  • Budget is not getting displayed in Report S_ALR_87013558

    Hi Friends, For project the budget is not getting displayed in Report S_ALR_87013558 though the budget is planned by TCode: CJ30 and released also by TCode: CJ32 Is there any setting in customising in information systems to display in the report. Ple

  • My MacBook Pro keeps crashing 2-6 times a day, please!

    Hey guys, over the last few weeks the KP increased a lot and I have no idea why. Unfortunately the backtrace/reasons for the KPs are always completely different so I hope one of you guys can help me out with this. Anonymous UUID:  BF278BF8-0869-27D0-

  • How do I keep a signature added to a pdf file checkout out of SharePoint using Safari?

    When I check out a pdf file from SharePoint using Safari, I have access to the acrobat tool using the adobe icon at the bottom of the Safari page. I I appear to be able to add my eSig. But, after checking the pdf file back into Safari and reopening i

  • How do I rip CDs on windows 8

    Just bought a Pavilion touch screen & don't know how to rip CDs to library This question was solved. View Solution.

  • Unknown Query Engine Error

    Post Author: Scott Miers CA Forum: Data Connectivity and SQL Hello, I have an application written in vb6 that opens a crystal 11 report. The report retrieves data from Microsoft SQL Server 2005. Occasionally, I get this error when opening large repor