Executing a command in the OS

I think I got the idea now, but if my line looks as follows:
Process p = Runtime.getRuntime().exec( "ls -t *.??")
I get an error message that says no such file or directory. it appears the wild card characters, * or ?? , or being ignored . Any suggestions? The commands works if typed in at the command line.
Thanks,
George

If you are going to use this I recommend you write a
shell script for the command that you wish to execute.
If you don't know how to do so it is simple.
#list.sh
#!/bin/bash
ls -t *.??
exit
#End of list.sh
then just execute it like this:
Process p = Runtime.getRuntime().exec("list.sh");Then you can use Process.getInputStream() to create a
stringbuffer of the listed directory or whatever it is
you want to do with it.
Hope that Helped.
--Ian                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • How execute a command on the Console from our prgm

    can any body let me know how do we execute a command on the Console from our prgm . . on a windows platform ..
    eg. a simple commant like "dir" or "cls" . . or whatever . . .
    i heard that it can be done by calling the native methods . . but how is that done???

    thankx for the quick reply . .
    for instance i wanna take a file from my local machine . .
    a c++ source code . . (myfile.cpp)
    i want to execute that on the prompt using c:\> tcc myfile.cpp
    and all these i mean reading the file from the HDD and giving it to the console and getting the output everything should be done by my prgm . .
    so basically the command which i usually run on the prompt i should be able to pass that command from my java prgm to the console and get that thing executed . .
    i hope i am clear now .. .

  • Executing two commands at the same time from Runtime.getRuntime

    Hi everybody,
    I m executing a command of imageMagic from javacode to crop and for changing the quality of image.The code is as below :
    String changeQuality = new String("convert " + originalImage
                        + " -crop " + imageWidth + "x" + imageHeight + "+" + imageX
                        + "+" + imageY + " -quality " + quality + " " + finalImage);
                   Runtime.getRuntime().exec(changeQuality);
    But before going to next page of jsp I want the size of the finalImage. So I m calling a new function from the base file, from which i m calling the above function, for getting the size of image:
    public String getSize(String finalImage) {
                   proc = Runtime.getRuntime().exec("identify " + finalImage);
    As identify cmd gives the size and various values of image but this command is showing the size zero. and if try to read the file then it shows FileNotFoundException.It means the file is not on the server.
    What should i do to execute both the command and getting the right result.
    Any help is appreciated.
    Thanks in advance.
    Vivek Kumar Gupta

    Hi everyone,
    Nobody ans my question but finally i got the ans of my question.
    I use a input stream for reading the first one imagemagic command. through this the second command execute after the first command finished its execution.
    And my images are now displaying without error.
    I know now you all are thinking how great mind I am!!! hai na
    Hmm woh to main hoon.
    post a question if u have over here. Perhaps i can solve your prob.

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • Using applet to execute a command on the server

    I want my applet to run a commend on a server. If I had a java program, I would have used
    Runtime.getRuntime().exec (cmd1, envArr, file)
    but I have an applet. so can I make it execute the command: "perl perlfile.pl" where perlfile.pl is on http://server/path/ ?
    the applet need some data that this perlfile creates.

    Send the command to a servlet and and get this to execute the command and return the response.
    This sounds like a good starting point to create a massive security hole.

  • Executing jar command from the java application

    Hi All,
    In my application i want to create a jar file with the existing class @ Runtime and want to download . But i tried to execute the jar command via Process.getRuntime, it throws IOException. Please guide me or give the solution

    PavithraKarthikeyan wrote:
    Please guide me or give the solutionQuestion your need for this. Why do you think you need to create the jar file.
    P.S. The jar command is only available if the user has the JDK installed so if he has only the JRE installed then you have a problem using Runtime.exec(). There are classes (java.util.jar.JarFile et al) that will allow you to jar files using Java code.

  • How to execute Sql command behind the submit button?

    Hello Dear,
    i design a Visual JFS page with 1 text box, 1 dropdown list, 1 date picker and 1 submit button. i have a database connected to my project with hibernate framework. now i want that whatever i change to textbox, dropdown list & date picker, when i press the submit button the information will insert to my database table. could any one help me with sample code or steps or procedure to accumplish my want?
    Regards,
    Taibur Rahman

    Hi,
    1) In baking bean you write one method in that you call Dao method or whatever persistence logic.
    2) In html or xhtml on submit button u add one attribute i.e action=#{BeanName.actionInsert}
    Since you are using visual JSF, simply double click on button, it'll automatically create action method in backing bean and their you write persistence logic.
    Thankyou
    Shivaprakash

  • How can I execute a command inside of a VM client from the VM host?

    Hi!
    I'm working on a set of scripts to automate MOC classroom installations using MDT and PowerShell. Sofar I've been able to automate everything except for the Rearm needed within the VM Clients. Is there any command (preferably PowerShell) that I can Launch
    on the VM host with which I can execute a command within the VM Client?
    Regards,
    Gerrit Deike
    If you think your to small to make a differnce, try going to bed with a mosquito in the room...

    If you wanted the pings to run in parallel, you could have this applet configure another applet to do the pinging, then remove it on the last run.  This will require an amount of programmatic logic, though.  If you wanted to keep things a bit simpler, add another applet that runs at 22:00 that configures a watchdog pinging applet, then a third applet that runs at 22:10 that removes the pinging applet.
    When it comes to embedded quotes when you configure your nested pinging applet, you'll need to use $q to stand for the embedded quotes.  You'll also need to configure:
    event manager environment q "

  • Execute powershell commands on a VM from the host.

    I’m wondering if it’s possible to execute PowerShell commands from the host that will be execute on a virtual machine.
    I have around 10 VM and I need to run the same command on all of it and I need to do the same in other 15 host.  
    None of the VM belong to the same domain.

    Yes, it's possible. 
    It's not recommended to do any administrative tasks from the host. You should remove the GUI and all roles from the host except things related to Hyper-V and used in your environment like Failover Clustering and MPIO. 
    As a best practice, set a Windows 8.1 VM as your management station and install RSAT tools on it including Hyper-V Manager. It also comes with Powershell modules you need to run Powershell commands and scripts against all your hosts and VMs.
    On the machines to be managed by Powershell you need to enable Powershell Remoting. In Server 2012 and above and Windows 8 and above this is enabled out of the box (even core versions). In older versions of Windows
    enable Powershell Remoting manually as shown in this post.
    On the management Win 8.1 VM that has RSAT installed, if the managed machines belong to the same domain as the managing station, you're good to go. If not, run this command on the managing station:
    winrm s winrm/config/client "@{TrustedHosts=""My2003Server,host2,host3,vm4""}"
    Execute your scripts against multiple machines by using Invoke-Command as in:
    'Computer1','Computer2','Computer3' | % {
    $Result = Invoke-Command -Computer $_ -ScriptBlock {
    Get-Process
    $Result
    This example, will execute the commands in the scriptblock on each of the 3 computers in line1, and return the result.
    For more information see
    Don Jones' Secrets of Powershell Remoting eBook.
    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________
    Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

  • How does one execute unix commands from within an applet?

    Greetings Folks,
    I've written a simple java applet that runs a unix command and then displays some information. The applet compiles fine, and runs perfectly from the command line on my unix system.
    However, when I point a browser at the applet from my desktop PC I get the following error as taken from the java console:
    Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.io.FilePermission <<ALL FILES>> execute)
    This is of course the first line in a long line of error messages. It appears that I am not able to execute a command on the unix system through my applet. I know the problem is with trying to execute a unix command since commenting it causes no error in the web browser. This is the command I'm using in java to execute the unix command:
    p = Runtime.getRuntime().exec("ps");
    Here's the html file on the unix system:
    <html>
    <head></head>
    <body>
    <appletcode=G.class height="250" width="400">
    Your browser does not support the applet tag.
    </applet>
    </body>
    </html>
    I won't list the java code since it is compiling and working on the command line. But, if you want to see it I'll provide it.
    I've done quite a bit of research on this and it seems that a great number of people have similar problems reading or executing files through java. I have yet to find a solution to this problem.
    Here are some details about my setup:
    Server:
    HP9000 running HP/UX 11.23
    Apache Web Server 2.0.35
    Java 1.5
    Desktop PC:
    Win2K Pro
    Internet Explorer 6
    Java 1.6
    If you have a solution I would be very grateful! This problem is keeping me from writing my application!
    thanks!
    kev

    Multi-posted.
    Already answered here http://forum.java.sun.com/thread.jspa?threadID=5225314&messageID=9916327#9916327
    Please don't multipost again!

  • Trying to find a way to execute from command prompt using java....

    I want to find a way to execute a command from the command line using a java program this is my code:
    import java.io.*;
    public class SQLHopefully
         public static void main(String[] args)
              try{
              Runtime rt = Runtime.getRuntime();
              Process proc = rt.exec("cmd /k start cmd.exe");
              OutputStream out = proc.getOutputStream();
              System.out.println(out);
              out.write("test.txt".getBytes()); //I THOUGHT THIS WOULD WORK
              InputStream stdin = proc.getErrorStream();
              InputStreamReader isr = new InputStreamReader(stdin);
              BufferedReader br = new BufferedReader(isr);
              String line = null;
              while ( (line = br.readLine()) != null) {
              System.out.println(line);
              stdin = proc.getInputStream();
              isr = new InputStreamReader(stdin);
              br = new BufferedReader(isr);
              line = null;
              while ( (line = br.readLine()) != null) {
              System.out.println(line);
              int exitVal;
              try {
              exitVal = proc.waitFor();
              } catch (InterruptedException e) {
              throw new IOException(e.getMessage());
              if (exitVal != 0) {
              throw new IOException("Exit value was " + exitVal ");
              }catch(IOException e)
              {System.out.println("ummmmm");}
    I hope my code is readable. I am trying to get the command prompt that comes up from the Runtime.exec() to run a file called "test.txt" I know it would be easier to just do it by executing it from java but I want to see if it is possible this way. I thought the out.write would do the trick but I was wrong. Somebody help please....
    Nate

    First read this article:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Second, you should probably send the Enter key to the shell if you want anything to happen. (Not that I know whether it will work, but I do know it won't work if you don't press Enter.)

  • Getting an Process Execute a command.

    Hi All,
    can I get the process created by the following code
    Process p = Runtime.getRuntime().exec("db2cmd");to execute some commands?
    My problem is I am getting a new window created by executing this line.
    My commands can be executed in the new window that gets created, how can I get a handle of this new window so that I can execute some commands in the new window.
    Any suggestions will be helpful.
    Regards
    Ayusman

    java.lang.ProcessBuilder
    it's in the standard api starting with jdk 1.5
    I don't see how it would help in this case though. Maybe there's something I'm just missing though.
    You might want to consider creating a batch file to run all the various commands you want to do in that window.

  • Bash function/script to execute multiple commands on same output

    Occasionally, I come across the need to pass the output of a single command to multiple others (without piping each to the next), so today, I wrote a [very] simple Bash script to accomplish the task.  Piping the output of a command to `tree' is much like piping it to `tee', except `tree' allows you to execute multiple commands on the same output, rather than only writing to log files:
    #!/bin/bash
    # tree -- pipes the output of one command to >= 1 other
    # Usage: command | tree 'command 1' 'command 2'
    doc=$( cat - )
    for arg in "$@"; do
    bash -c "${arg}" <<EOF
    ${doc}
    EOF
    done
    An example of its usage:
    $ echo -e "1 2 3\n4 5 6" | tree 'grep 1' 'grep 4' "grep 1 | tee grep.log | awk '{print \$2}'"
    1 2 3
    4 5 6
    2
    $ cat grep.log
    1 2 3
    Though not elaborate, the script gets the job done.
    Last edited by deltaecho (2009-03-10 20:34:01)

    Xyne wrote:
    You could always call it "the Ukrainian Pipe"
    (if you can't laugh at this, you either need to loosen up or make a point to follow (annual) current events)
    That was a good one

  • How to execute unix command through odi and store the result in table

    I have to reconcile  if data is loaded in table from csv file or not . I have to create a oracle data integrator package/interface/procedure to execute unix command to count number of rows in the csv files and store the count result in a table then i have to query the loaded table and count number of rows there and store in the table and have to compare is counts are same or not,  Please assist me how to make package/interface/procedure to  execute unix command and store result in oracle table.
    Thanks in Advance

    Use ODI OS command tool in the ODI package.
    create an interface in ODI using LKM File to Sql and the output file generated with the csv file's row count as a source and the db table(where the count needs to be stored) as a target

  • Error when I execute an application with the java command in a DOS prompt

    Hi:
    I have a trouble. I edit the most simple program in Java: hello.java
    In DOS prompt, I compile the program. The result is the file hello.class
    c:\> javac hello.java
    However, I try to execute this program with the command java
    c:\> java hello
    and the DOS prompt send me an error like this: Java.exe has a problem and must be closed.
    I press the option "Don't send". After this, the DOS prompt returns empty and it doesnt execute the application:
    c:\>
    By the way, in an IDE editor like Gel, the file hello.java is compiled and executed correctly without problems.
    I edited other simple Java files, I compiled them succesfully and I can't run them in a DOS pormpt. The result is the same dialog box: "Java.exe has a problem and must be closed".
    The question is: Why don't these programs run in a DOS prompt?
    My Operating System is Microsoft Windows XP and the Java compiler version is: 1.6.0_13
    Thanks in advanced.

    Hi again:
    What happens when you type "java -version"?
    Answer:
    java version "1.2"
    Classic VM (build JDK-1.2-V, native threads)
    What is the value of your %PATH%?
    Answer:
    Path=E:\oracle\product\10.2.0\db_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Archivos de programa\Archivos comunes\Adaptec Shared\System;C:\Archivos de programa\Executive Software\DiskeeperLite\;C:\Archivos de programa\QuickTime\QTSystem\;C:\Archivos de programa\Java\jdk1.6.0_13\bin;C:\Archivos de programa\Microsoft SQL Server\80\Tools\Binn\;e:\Microsoft SQL Server\90\Tools\binn\;C:\BITWARE\;C:\Archivos de programa\Archivos comunes\Ahead\Lib\
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
    Have you considered running Linux?
    Answer: No, because Linux is more complex.
    Additional information:
    My Operating System is: Microsoft Windows XP Profesional Version 2002, Service Pack 3, running on an Intel Pentium 4, CPU 2.4 Ghz, RAM: 2.23 Gb

Maybe you are looking for

  • Default ware house in Document

    Hi All, I have a default warehouse 06 for finished goods. But I will be transfering that to 11 when the quality check is completed. My question is can we have default warehouse  at document level. i.e when I open a sales quotation in that wherehouse

  • SP with xp_cmdshell gives an error in the MessageQueue, but executes successfully in SSMS.

    Hi All, I have a SP, which calls xp_cmdshell in it. This SP is being used in a MessageQueue.  The SQL server and Agent services are configured using a Domain service account, and this service account has a login under the sysadmin server role as well

  • Mouse stops working, touchpad configuration lost after resync

    Hi folks, Been having issues with mouse devices since the switch to SystemD. My Logitech G400 mouse works on the GDM menu for a few seconds, then stops. Re-plugging the mouse does not bring it back, though it does still show under lsusb. Maybe in a r

  • Migration assistant to look at ext HD

    I was told by a mac genius that I could use migration assistant to get files from an external HD. It doesn't recognize any of my drives, internal or external that are hooked up to my mac. Am I missing something? thanks

  • Skype Freezes randomly when I am typing to friends...

    Hello, Whenever I am typing to any friend in skype, skype will randomly freeze. After about a minute or so, it will unfreeze, and sometimes it just crashes and I have to restart. This happened ONLY after the latest version update of 7.2.0.103. I have