Parsing java command line output to a gui

Dear All,
I am trying to implement a search engine for a project, i have a java file called Searcher.java, which searches for a particular text or sentence and gives the output based on the number of hits on a particular document, the document with the max hits is displayed first and so on,all the documents are are stored in a text file, I am trying to create a GUI for this file, the gui would consist of a text box,submit button,a list and a text area , when a user enters the text to search all the entries are displayed in the list box and upon clicking the individual item in the list the description should open up in the text area.
The problem i am encountering is that i am not able to parse the output of the searcher.java file onto the GUI, i have no clue as to how to implement it , i would really appreciate it if anyone could help me out.
the code for Searcher.java is as follows
import java.util.*;
public class Searcher {
/** Specify the work directory !! */
private static final String rootDir = "C:/HR/GUIAssign/";//on PC
// private static final String rootDir = "/research/gm/Java/IR/"; // on Unix
private static final String stopWordFile = "iStopWords.txt";
private static final String docCollFile = "iDocColl.txt";
private static final String invertedIndexFile = "ioInvertedIndex.txt";
private StopWordSet stopWords = new StopWordSet(rootDir + stopWordFile);
private Stemmer stemmer = new Stemmer();
private TextTokenizer tok;
private TextParser parser;
private InvertedIndex inv;
/** Creates a new instance of Searcher */
public Searcher(TextTokenizer tok, TextParser parser) {
this.tok = tok;
this.parser = parser;
ReaderWriter rw = new TextFileReaderWriter(rootDir);
inv = rw.readInvertedIndex(invertedIndexFile);
List search(String query) {
System.out.println("\nSearching for <" + query + ">.");
List hits = new ArrayList();
int nbOfDocs = parser.getNbOfReadDocs();
System.out.println("\nSearching for <" + query + "> among " + nbOfDocs +
" documents.\n");
double scores[] = new double[nbOfDocs]; // initial values 0.0
String term;
tok.setText(query);
while(tok.hasMore()) {
System.out.println("\nNext term: ");
term = tok.nextToken();
System.out.println(term);
if(stopWords.contains(term))
continue; // this terms can be ignored
term = stemmer.stem(term); // apply the stemmer to get the root
System.out.println("\n\nInfo on the term \"" + term + "\":");
IndexTerm indexTerm = inv.getIndexTerm(term);
if(indexTerm == null)
System.out.print("Not in the vocabulary.");
else {
System.out.print("It appears " + indexTerm.getTermFreq() + " times, in "
+ indexTerm.getDocFreq() + " documents:\t");
Iterator itr = indexTerm.getIterator();
while(itr.hasNext()) {
DocFreq docFreq = (DocFreq) itr.next();
scores[docFreq.getDocId()] += docFreq.getFreq() /* / indexTerm.getDocFreq() */ ;
// create hits from documents that have non-zero scores
for(int i = 0; i < nbOfDocs; i++)
if(scores[i] > 0.0)
hits.add(new Hit(i, scores));
// sort them in descending order of scores
Collections.sort(hits, new Hit.CompareByScore());
return hits;
* @param args the command line arguments
public static void main(String[] args) {
TextTokenizer tok = TextTokenizer.getTokenizer("alpha");
TextParser parser = new DummyParser(rootDir, tok);
Searcher searcher = new Searcher(tok, parser);
List hits = searcher.search("trade and board coffee, stock x is common");
Iterator it = hits.iterator();
while(it.hasNext()) {
Hit hit = (Hit) it.next();
int index = hit.getDocIndex();
Doc doc = parser.getDoc(index);
System.out.println("\n\nDoc " + index + " has a score of: " +
hit.getScore() + "\n*** " + doc.getTitle() + " ***\n" +
doc.getText());
this code runs perfectly and gives the output on the command line
the code for the GUI is as follows
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
import javax.swing.event.*;
public class HRSearch extends JFrame implements ActionListener {
// keep references to all event sources
private JLabel searchLabel;
private JTextField searchField ;
private JButton submitButton ;
private JScrollPane searchScrollPane;
private JTextArea textArea ;
public HRSearch()
          Container contentPane = /*this.*/getContentPane( ) ;
          JPanel submitPanel = new JPanel();
          submitPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
          searchLabel = new JLabel("Search: ");
          searchLabel.setEnabled(false);
          submitPanel.add(searchLabel);
          searchField = new JTextField("", 20) ;
          searchField.setEditable(true) ;
          searchField.addActionListener(this) ;
          searchField.setEnabled(false);
          submitPanel.add(searchField) ;
          submitButton = new JButton("Submit") ;
          submitButton.addActionListener(this) ;
          submitButton.setEnabled(false);
          submitPanel.add(submitButton);
          contentPane.add(submitPanel, BorderLayout.NORTH);
JPanel mainPanel = new JPanel() ;
               mainPanel.setLayout(new FlowLayout(FlowLayout.LEFT)) ;
          JList searchList = new JList() ;
          // searchList.setEditable(false) ;
          searchList.setVisibleRowCount(20) ;
          searchScrollPane = new JScrollPane(searchList);
          mainPanel.add(searchScrollPane) ;
          textArea = new JTextArea("", 20, 40) ;
          textArea.setEditable(false) ;
          mainPanel.add(new JScrollPane(textArea) /*, BorderLayout.CENTER */) ;
          contentPane.add(mainPanel, BorderLayout.CENTER) ;
public void actionPerformed(ActionEvent e) {
String text ; // response to action event
Object source = e.getSource( ) ;
if (source != searchField && source != submitButton)
return; // not interested in other actions
// get text, trim leading and trailing spaces
text = searchField.getText( ).trim() ;
try {
textArea.setText(textArea.getText() + "\n" + " " );
catch(NumberFormatException exc) {
JOptionPane.showMessageDialog(
this, // address of "parent" or "anchor" frame
"Not a number !", // the error message
"Number Format Exception", // title of this modal dialogue
JOptionPane.ERROR_MESSAGE // nature of this dialoge
public static void main(String args[]) {
          final JFrame f = new HRSearch();
          // f.setBounds(100,100,500,450);
          f.pack();
          f.setVisible(true);
          f.setDefaultCloseOperation(EXIT_ON_CLOSE);
i am stuck at this point and dont know what to do , please help me out.
regards
harsha

I'm not positive I understand your problem... but let me recap what I think it is, then provide a solution:
Your searched program can be run from the command line, and prints out (using system.out) the data you want. But NOW you want to create a GUI class, that intercepts that output, and displays it on the screen, and you can't because its going to the output stream and you're GUI isn't able to get it.
If this is the case, what you can do is add two constructors to your Searcher class:
public Searcher()
this(System.out);
public Searcher(OutputStream out)
this.out = out;
The idea being, that if you don't specify an output stream, the output goes to the console like normal. But if you do specify an output stream, the data gets fed back to you. So then in your GUI, you can do some binding of PipedInputStream and PipedOutputStream so when the Searcher class prints out, it comes right through the pipe into your GUI where you are waiting to read it.
If this wasn't your problem, sorry :(
Best,
-Riyad

Similar Messages

  • Importing .eex using Java Command Line on Unix (Licence required?)

    Hiall,
    We're looking into scripting our deploy process to reduce the amount of manual intervention required. We'll be importing the eex from a Unix box and was wondering what the licencing restrictions are on using the Java Command Line tools.
    Do we need a licence for them? Which kind? Desktop or Administrator?
    We already have Desktop licences but would rather not have to buy an additional one just for this process.
    Thanks for any help you can offer.

    Hi
    The Java Command Line Utility for the EUL is licensed with the Admin edition so you'll need to purchase at least one Admin license (at current prices these are $5,000 per administrator).
    Personally, I've always found scripting to be as much a manual process as entering the Admin tool and using the GUI interface.
    Best wishes
    Michael

  • How To Parse The Command Line?

    Hello,dear. When I writing a C/S mode application,which performing download and upload files between the FTP server and the clients, I encountered the problem of parsing the command line.
    I intend to download file from the server side ,using this following format ,which is composed by four arguments:
    ftp>receive server's IPaddress portnumber filename
    The problem is I don't know how to parse the command line and store them to some objects and using it.
    I'm right here waiting for the nice problem-shooter.
    Thanks for reading my poor expression.

    In your console application main class
    public static void main(String[] args)
    // code
    args is a sting array with the command
    line itemsI think you missed the point or forgot the ":-)". This is the "Socket", not the "New to Java" forum.

  • Capturing command line output to a file possible?

    Hi, i am in need of capturing the command line output to a txt file and need some suggestions on how to do it.
    I have two classes, class A is the one with all the methods and outputs text to the command line (using System.out.print). class B is the one that calls the methods and needs to record the command line output to a file.
    Now the problem i face is not all the output is going to be written to a file and not all the output is going to be displayed on the command line. eg. class B will have a way to select the output mode which is either both to a file and command line or just to a file and display nothing on the command line.
    Is what i am asking even possible? Any suggestions would be great!

    Here is a class I found on the forum that does basically what you need. Just change the code that is updating a Document to write to a file:
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class ConsoleOutputStream extends OutputStream
         private Document document = null;
         private ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
         private PrintStream ps = null;
         public ConsoleOutputStream(Document document, PrintStream ps)
              this.document = document;
              this.ps = ps;
         public void write(int b)
              outputStream.write (b);
         public void flush() throws IOException
              super.flush();
              try
                   if (document != null)
                        document.insertString (document.getLength (),
                             new String (outputStream.toByteArray ()), null);
                   if (ps != null)
                        ps.write (outputStream.toByteArray ());
                   outputStream.reset ();
              catch(Exception e) {}
         public static void main(String[] args)
              JTextArea textArea = new JTextArea();
              JScrollPane scrollPane = new JScrollPane( textArea );
              JFrame frame = new JFrame("Redirect Output");
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.getContentPane().add( scrollPane );
              frame.setSize(300, 600);
              frame.setVisible(true);
              System.setOut( new PrintStream(
                   new ConsoleOutputStream (textArea.getDocument (), System.out), true));
              System.setErr( new PrintStream(
                   new ConsoleOutputStream (textArea.getDocument (), null), true));
              Timer timer = new Timer(1000, new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        System.out.println( new java.util.Date().toString() );
                        System.err.println( System.currentTimeMillis() );
              timer.start();
    }

  • Where is the documentation on the Java command line options.

    I know you can get them by running java.exe, but does Sun have a web page with a little more detail?

    Googling for
    java command line options site:java.sun.com
    Found this for 1.4. I imagine you should be able to find something similar for 5.0.
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html

  • Java command line purge not working after applying MLR 10

    Hi Gurus,
    After applying the latest patch MLR 10,
    java command line purge does not seem to work. I'm using the command
    java -ms1024M -mx1024M oracle.tip.repos.purge.PurgeManager purgeRuntime -start 07-APR-2009 -end 22-MAY-2009 Complete
    Before running the command i have set the environment using setenv.bat present in ip\install directory.
    Below error is observed when trying to purge the messages
    java -ms1024M -mx1024M oracle.tip.repos.purge
    .PurgeManager purgeRuntime -start 07-APR-2009 -end 22-MAY-2009 Complete
    Purge started, please wait...
    Purge failed
    Error -: AIP-11016: SQL error: java.sql.SQLException: ORA-06550: line 1, colum
    n 7:
    PLS-00905: object B2B.PURGE_RUNTIME is invalid
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    at oracle.tip.repos.purge.PurgeManager.main(PurgeManager.java:1454)
    Caused by: java.sql.SQLException: ORA-06550: line 1, column 7:
    PLS-00905: object B2B.PURGE_RUNTIME is invalid
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
    :124)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:315)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:281)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:638)
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.
    java:183)
    at oracle.jdbc.driver.T4CCallableStatement.execute_for_rows(T4CCallableS
    tatement.java:872)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStateme
    nt.java:1085)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePrep
    aredStatement.java:2983)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePrepar
    edStatement.java:3056)
    at oracle.jdbc.driver.OracleCallableStatement.executeUpdate(OracleCallab
    leStatement.java:4295)
    at oracle.tip.repos.purge.PurgeManager.main(PurgeManager.java:1449)
    Kindly let me know if any post install scripts needs to be run ?
    Or is there any thing else i have missed.
    Thanks in advance,
    Regards,
    Cema
    Edited by: Cema on May 22, 2009 12:14 PM

    Hi Cema,
    In MLR 10 these two bugs have been added with others (you can see in patch read me file)-
    8432093 - AUTOMATE THE POST PATCH INSTRUCTION SCRIPTS FROM MLR 10 ONWARDS
    8339176 - B2B PURGE_RUNTIME PROCEDURE DOES NOT DELETE ALL TIP_WIREMESSAGE_RT RECORDS
    Bug 8432093 tells clearly that there is no need of running any post installation script from MLR 10 onwards, so you have not missed anything like post installation script.
    Bug 8339176 has addressed the PURGE_RUNTIME functionality for deleting messages. From your earlier posts it seems that you got some errors while applying this patch. Please make sure that patch is successfully installed on your system.
    Regards,
    Anuj

  • JAVA command line options -cp and -jar don't work together?

    Running JSDK 1.4.2 under Windows. I have a Java application that tries to dynamically load a class name that the user enters as follows:
    try {
    classResult = java.lang.Class.forName(strFilterName);
    catch (ExceptionInInitializerError e) {
    strErrorMessage = "ExceptionInInitializerError loading class: " + strFilterName;
    catch (LinkageError e) {
    strErrorMessage = "LinkageError loading class: " + strFilterName;
    catch (ClassNotFoundException e) {
    strErrorMessage = "ClassNotFoundException loading class: " + strFilterName;
    This works fine if the classes that make up my application are left as class files in the classpath, but fails to work if they have been collected and run from a JAR file. Note: I can even dynamically load the class when running from the JAR file, if the class I'm trying to load is within that JAR file too. The problem really occurrs when the dynamically loaded class is located someplace else in my classpath. I've tried using various combinations of the "-cp" and "-jar" Java command line options - but when loading and running from a JAR file - the "-cp" parameters seem to be ignored. Is this a bug? Has anyone ever seen this before?
    I run my program from the JAR file using this command:
    java -cp .;e:\entmgr\filters -jar EntMgr.jar
    Where "e:\entmgr\filters" is where the class I'm trying to dynamically load is. (This class has no package name, but loads perfectly as long as I'm not running the application from the JAR file). The class name specified by the user has to be fully specified with a package name (if it has one).
    I have tried forcing the "java.lang.Class.forName(strFilterName);" call to use the system class loader, the parent of the system class loaded, and even the null bootstrap class loader - all with no success.
    I am suspecting that the class loader that is loading and running my main program from the JAR file, is just not paying any attention to the "-cp" parameter when the "-jar" parameter is present. Indeed, I have never seen any change in the failure, no matter what I put in the "-cp" parameter when using the JAR file.
    When I run this without using the JAR file, here is the command I execute:
    java -cp .;davidp\snmp;filters davidp.snmp.EntMgr
    Where this is executed in a directory that has a "filters" and "davidp\snmp" directory. In this case, because the "filters" directory is in my class path - I can dynamically load my class from it using just its simple name (i.e. "TestTrapFilter").
    So, is there some bug that precludes the "-cp" parameter from working correctly when the "-jar" parameter is used? Is there some other way to initialize or set up the classloader I'm using, so it can find things outside of the JAR file I'm running from? I would hope that it is possible to get the same behavior from my program, no matter if it is run from a JAR file or not.
    Thanks for any assistence!
    Dave

    These posts are pretty old, but this page came up in a google search while I was having the same problem, so I thought I would throw my own (Later found) solution in.
    The -cp and -jar options did not work together for me, but I later learned that they didn't really have to (and you don't have to mess with jar manifest files).
    While on the command line, if you want to set a specific class path and also run a jar, all you need to do is add the jar to whatever extra class path you need to use in the -cp <arg>, and then specify which class you want run from inside the jar.
    IE:
    java -cp <YourSpecialClasspath>: <PathToJar> <ClassToRunInsideOfJar>
    in my case it was like:
    java -cp /home/user/WebRCP.jar:./StandaloneInstaller.jar InstallLoader
    Remember to put a ":" in between the two arguments for the class path (-cp).
    Hope this helps someone in the future,
    -Josh

  • Why not all jars picked up by ojdeloy and how to generate build.xml from command line and not JDEV GUI - quick question

    Hi All
    We have 11.1.1.7 ojdeploy to compile our app.
    We notice in the log that not all jars are used in classpath arguments when we explicitly set them up for compilation.
    eg:
      <path id="classpath">
        <pathelement location="../../Oracle/Middleware/oracle_common/modules/oracle.adf.share_11.1.1/commons-el.jar"/>
        <pathelement location="../../Oracle/Middleware/oracle_common/modules/oracle.adf.share_11.1.1/jsp-el-api.jar"/>
        <pathelement location="../../Oracle/Middleware/oracle_common/modules/oracle.adf.share_11.1.1/oracle-el.jar"/>
        <pathelement location="interface/public_html/WEB-INF/lib/a.jar"/>
        <pathelement location="interface/public_html/WEB-INF/lib/b.jar"/>
        <pathelement location="interface/public_html/WEB-INF/lib/c.jar"/>
        <pathelement location="interface/public_html/WEB-INF/lib/d.jar"/>
    </path>
    Log Output -
    [ora:ojdeploy] /path/to/Oracle/Middleware/jdk160_24/bin/javac
    [ora:ojdeploy] -g
      [ora:ojdeploy] -Xlint:all
      [ora:ojdeploy] -Xlint:-cast
    [ora:ojdeploy] -Xlint:-empty
      [ora:ojdeploy] -Xlint:-fallthrough
      [ora:ojdeploy] -Xlint:-path
      [ora:ojdeploy] -Xlint:-serial
      [ora:ojdeploy] -Xlint:-unchecked
      [ora:ojdeploy] -source 1.6
      [ora:ojdeploy] -target 1.6
      [ora:ojdeploy] -verbose
      [ora:ojdeploy] -encoding Cp1252
      [ora:ojdeploy] -classpath
    [ora:ojdeploy] /path/to/Oracle/Middleware/jdk160_24/jre/lib/resources.jar:
    [ora:ojdeploy] /path/to/Oracle/Middleware/jdk160_24/jre/lib/rt.jar:
      [ora:ojdeploy] /path/to/Oracle/Middleware/jdk160_24/jre/lib/jsse.jar:
        [ora:ojdeploy] /path/to/interface/public_html/WEB-INF/lib/a.jar"/>
        [ora:ojdeploy] /path/to/interface/public_html/WEB-INF/lib/c.jar"/>
    1- Is it because it depends on how jpr or jws are configured ?
    2- How can we automatically generate a build file of the application from command-line (as opposed to using Jdev IDE to click to generate a build.xml) ?

    The first  warning is happening because you're stating drivers for input devices without need. You haven't disabled hotplug so evdev gets used instead of kbd. This is normal, and you should change the driver line from kbd to evdev so that whatever options (if any) you've specified for the keyboard get parsed.
    The second warning is about you not installing acpid.
    The third I have no idea about, but look at the synaptics wiki. None of the (WW) are related to your video card.
    And every card that has 2 or more output ports show up as "two cards". You also don't need to specify the pci port in xorg.conf. edit: this is the general case with laptops, might be different for desktops.
    When I do lspci -v I get:
    00:02.0 VGA compatible controller: Intel Corporation Mobile 945GME Express Integrated Graphics Controller (rev 03) (prog-if 00 [VGA controller])
    Subsystem: Micro-Star International Co., Ltd. Device 0110
    Flags: bus master, fast devsel, latency 0, IRQ 16
    Memory at dfe80000 (32-bit, non-prefetchable) [size=512K]
    I/O ports at d0f0 [size=8]
    Memory at c0000000 (32-bit, prefetchable) [size=256M]
    Memory at dff00000 (32-bit, non-prefetchable) [size=256K]
    Expansion ROM at <unassigned> [disabled]
    Capabilities: <access denied>
    00:02.1 Display controller: Intel Corporation Mobile 945GM/GMS/GME, 943/940GML Express Integrated Graphics Controller (rev 03)
    Subsystem: Micro-Star International Co., Ltd. Device 0110
    Flags: bus master, fast devsel, latency 0
    Memory at dfe00000 (32-bit, non-prefetchable) [size=512K]
    Capabilities: <access denied>
    And it doesn't matter if it errs in trying to sli up with it self. That's just not a possibility.
    Last edited by gog (2009-10-15 23:59:49)

  • Mashed/compressed command line output

    This is rather hard to describe, but after installing Arch on a new machine not long ago, I noticed that in the output of certain programs, some characters were partially or entirely hidden behind others.  That is, it appears that certain letters are mostly missing, but little bits of them are still visible behind characters that come later on in the output.  If I select the output with my mouse, and copy and paste somewhere else, the entire output is there...it's just not all visible on the command line.  Though, as I select with my mouse, the specific text my mouse is over becomes visible and other, adjacent characters are hidden.  So far I've seen this running yaourt, as well as in vim (which is really a pain).  I use Konsole.
    Here's a screenshot, showing the output of `yaourt -Ss digikam`:
    Notice how various text fields seem to run into each other, and the end of each field gets clipped.  As I said, I see the same behavior within vim, so it's not limited to the output of any particular program.  Any ideas what's causing this?  Is it a Konsole thing, or could it be related to X somehow, or maybe something else I haven't thought of?

    I am writing a program that runs a load utility via a
    class that returns the load utilities output via a
    string. There is a certain part of this output which
    i need to determine if the program has successfully
    completed. I am looking for suggestions on how to
    accomplish this. Below is an example of the commands
    output.
    Rows Read : 30000
    Rows Rejected : 0
    Rows Loaded : 30000
    Rows Committed: 30000What constitutes a successful run?
    Might want to take a look at the String.startsWith() and String.indexOf() methods:
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

  • Java command line programming in windows

    Here's what I want to do:
    -write .java files in a text editor
    -compile and run them from a command line, rather than using a
    compiler like codewarrior or MS J++
    Here's my problem:
    In a program that produces output, I can't seem to find a way to
    retain the output that goes off the screen in a DOS window. Is there
    a way to enable scrolling in a DOS window, or are there any
    alternative command line terminals for Windows? Any suggestions
    would be greatly appreciated.

    I think you can increase the Screen Buffer size which should give you a scroll bar. For this right click on the icon on the top left of the DOS window -select Properties - Go to Layout tab.
    Another option will be to redirect the output to a file
    java SomeClass > log.txt
    Hope this helps.

  • Execute external java command line in Java

    But I can not get any result ( It does not create file test.svg) . the code is as follow
    Runtime.getRuntime().exec("java -jar c:/XSLT/saxon7.jar ../webapps/wfscontroller/gml.xml ../webapps/wfscontroller/SVG.xsl > ../webapps/wfscontroller/test.svg");
    If I execute "java -jar c:/XSLT/saxon7.jar ../webapps/wfscontroller/gml.xml ../webapps/wfscontroller/SVG.xsl > ../webapps/wfscontroller/test.svg" in DOS command. it works.
    Anybody knows what happened?
    Many thanks in advance.

    The > is interpreted by the shell. When you use Runtime.exec, you don't go through the shell, you exec the executable directory. So when you exec that command, you're passing ">" as an argument to "java -jar c:/...", and chances are the main() method in that doesn't interpret ">".
    So the upshot is you can't use ">", "|", "<", etc., that you can in a shell, with Runtime.exec().
    Other options are to run a batch file which invokes that command line.
    Or, you can get the standard output from the exec'ed process, and save it to a new file yourself.

  • Java command line run code question?

    hello all:
    I met a question and want to get some suggestion from you.
    I have one file TestOne.java located in
    folder "c:\temp\aaa" which contains only one file(TestOne.java).
    package samples.java2beginner.gui;
    import java.io.*;
    public class TestOne {
         public static void main(String[] args) {
                System.out.println("hello world");
    }I use the following command to compile this java code:
    c:\temp\aaa\javac TestOne.java // everything is ok.
    In order to run this program, I have to manually create
    folder hierarch "samples\java2beginner\gui" in "c:\temp\aaa" and
    use the command
    c:\temp\aaa\java samples.java2beginner.gui.TestOne to run this program.
    My question is: is there any method that I can directly run
    this java program without manually create "samples\java2beginner\gui"
    which is annoying?
    thank you

    hello atmguy and DevMentee:
    Thank you for your great suggestion.
    I guess I didn't say my question clearly.
    The class file compiled from TestOne.java is TestOne.class which cannot be modified.(so i cannot erase the package line or any kind of modification)
    I want to run the java program from command line.
    currently I have to create "samples\java2beginner\gui" and copy TestOne.class to there.
    My question is: given one class file only(so you only get the TestOne.class),
    do you have method to run it from command line?
    so at this case you don't know which package the .class belongs to.
    You might think my question is silly. The reason I posted the question because
    I found problems when I use jode to decompiler a class file.
    JODE is a java decompiler from jode.sourceforge.net
    Given the above class file "TestOne.class", I cannot use jode to decompile it, because I have to run jode with the following method:
    c:\temp\aaa\java jode.decompiler.Main -cp samples.java2beginner.gui.TestOne
    which in fact is impossible given only .class file?
    because the reason we use jode is to decompiler, how can you know the package
    structure before decompile?!
    so the problem came to my original question.
    thank you all.

  • How to display Runtime.exec() command line output via swing

    Hi all, I'm new to java but have a pretty good understanding of it. I'm just not familiar with all the different classes. I'm having trouble capturing the output from a command I'm running from my program. I'm using Runtime.exec(cmdarray) and I'm trying to display the output/results to a JFrame. Once I get the output to display in a JFrame, I'd like it to be almost like a java command prompt where I can type into it incase the command requires user interaction.
    The command executes fine, but I just don't know how to get the results of the command when executed. The command is executed when I click a JButton, which I'd like to then open a JFrame, Popup window or something to display the command results while allowing user interaction.
    Any examples would be appreciated.
    Thank you for your help in advance and I apologize if I'm not clear.

    You can get the standard output of the program with Process.getInputStream. (It's output from the process, but input to your program.)
    This assumes of course that the program you're running is a console program that reads/writes to standard input/output.
    In fact, you really should read from standard output and standard error from the process you start, even if you're not planning to use them. Read this:
    When Runtime Exec Won't

  • Can Only Add Cert Template through Command Line (Can't use GUI)

    I am hoping somebody can figure this issue out.
    We have a Server 2008 Enterprise 32 Bit server running AD certificate Services.  Plan was to migrate the server to 2012 R2 (64 bit).  I went through the migration guide and everything was going great until I went to add a new template after the
    fact.  After duplicating a template and changing the settings, I went to Cert Templates on the CA and did a:  new --> Certificate Template to Issue.  Sadly, the cert I created did not show up.  I deleted it, and did it again, still it
    did not show up.  I figured something was wrong with the migration since this work previously, so I followed the guide and recovered everything back to my original 2008 Enterprise server. 
    Everything is back to where it was before except this problem of not being able to add new certs to issue through the GUI has stayed.  I can add them using command line: 
    certutil -setcatemplates +TemplateName  and they show up and are usable.
    Why can't I do this through the GUI? 

    Hi,
    In additon to above suggestion, hope the below link be helpful also:
    Can’t Create a New Certificate Template to Issue?
    Regards,
    Yan Li
    TechNet Subscriber Support
    If you are
    TechNet Subscription
    user and have any feedback on our support quality, please send your feedback
    here.
    Regards, Yan Li

  • Java command line in File adapter

    Hi all,
    In my receiver file adapter (FTP), I want to use the option "Run operating system command after message processing".  In the command I want to execute a java class.  Can anybody have information about how to do that ?
    My command line in the following : "java myPackage.MyClass %F". This command line works fine on my machine but I don't know how to do when on XI File Adapter (where to set the jar file, ...)
    Thanks in advance,
    Laurence

    Hi Laurence
    XI Command Line Functions::
    /people/michal.krawczyk2/blog/2007/02/08/xipi-command-line-sample-functions
    1)Windows batch Commands::
    http://labmice.techtarget.com/articles/batchcmds.htm
    2)Linux:
    /people/michal.krawczyk2/blog/2005/08/17/xi-operation-system-command--error-catching
    regards
    Piyush
    Pl: reward points if it is helpful.

Maybe you are looking for