Using Command Line Arguments with JAVA

Hi,
we are using an app called ImageMagick to scale and modify images before they are uploaded to a webserver.
ImageMagick is called from our Objectiv-C app via
command line.
is there a way to this in Java?
Regards
Eckbert

So, ur question is not developing a Java application that
will do the 'image conversion'; but, your message
conveys that u want to know how to invoke a Java program built by 'imagemagick' that takes command line arguments?
Am I right?
If that's the case, u must look into the documentation
given along with the download'ed piece of software
for identifying the 'starting point of the program'. i.e., the
class that contains the 'main' method! And after you
identify that class [Eg. ImageMagickStart] then you'll
have to invoke as follows:
[you must have Java installed in ur system!]
c:>java ImageMagickStart
If the program was written intelligently it must print all
the command-line arguments required by the above
program by executing the above command, and from that
you can identify!
-RK

Similar Messages

  • Read in file name + path using command line arguments

    Hi guys,
    I am trying to use command line arguments to read in the name of two files. The code below works as long as the files are on the class path.
    public class cmdLineArguments {
         public static void main(String[] args) {
              String xmlFile1 = args[0];
                    String xmlFile2 = args[1];
              System.out.println ("\nXmlFile1: " + args[0] + "\nXmlFile2: " + args[1]);
    }I would like to be able to read files that are not on the class path as well by entering their full path along with their names.
    In other words, It works if I type:
    C:\Documents and Settings\user\workspace\CmdLineArgs\src>java cmdLineArgs file1.xml file2.xmlbut not if I type:
    C:\Documents and Settings\user\workspace\CmdLineArgs\src>java cmdLineArgs c:\Documents and Settings\user\desktop\file1.xml c:\Documents and Settings\user\desktop\file2.xmlWould anyone please explain how I can edit the code to make it work? I guess I could take them both as a String, modify them manually (add a \ to it etc) but is there an easier way to do it? Even a reference to a tutorial, article etc about this would be very much appreciated.
    Also, any idea why a code would compile and run fine in Eclipse but would create an error from command line?
    Thanks a lot.

    You need to learn about cmd.exe which is used to process the command line. The arguments passed to any program is the command line split at white space so your command line arguments of
    c:\Documents and Settings\user\desktop\file1.xml c:\Documents and Settings\user\desktop\file2.xmlis turned into an array of
    "c:\Documents", "and", "Settings\user\desktop\file1.xml", "c:\Documents", "and", "Settings\user\desktop\file2.xml"In other words instead of 2 arguments you actually have 6.
    To get round this the file names need to be quoted
    java cmdLineArgs "c:\Documents and Settings\user\desktop\file1.xml" "c:\Documents and Settings\user\desktop\file2.xml"

  • Numerical Command-Line Arguments in Java

    Hi I am new to Java and am a little confused about setting up command-line arguments. From what I have read, the arguments are put in the args array of the main method.
    So accessing or using them would use args[n] right?
    But the args is a string array (String[] args). Therefore what would I need to do if I wanted to treat the arguments as numbers and not strings? E.g. I wanted to apply mathematical functions to the arguments.
    I believe to do this I would need a Integer.parseInt( string ).
    This is what I have tried:
    public static void main(String[] args) {
              int firstArg = Integer.parseInt(args[1]);
              System.out.println(firstArg);
    where argument 1 is "23".
    This compiles but I get a Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
         at the "int firstArg = Integer.parseInt(args[1]);" line.
    Can someone tell me what I am doing wrong and a small over view on command line arguments would also be welcome :D.
    Thanks

    Oh yeah.. I need to tattoo args[0] to my forehead. Thanks its now working.
    Edited by: Sunny_B on Apr 20, 2008 1:21 PM

  • Possible to use command line argument in project file?

    In my CI build process I would like to have a command line argument "customer" that should be used in the project file to include customer related files into the project like this:
    <Content Include="..\customers\%(customer)\*">
      <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
    </Content>
    Is that possible?

    Hi pkursawe,
    Try to use the Copy task, topy the custom files into the project, then add these files into the ItemGroup, check this blog post:
    How To: Recursively Copy Files Using the <Copy> Task
    The wildcard will help you to add related files into the project.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Prevent Startup Form from Loading using Command Line Arguments

    Hi there
    I'm developing a VB.NET windows forms application in VS2013.
    The application will have 2 ways of being executed, one being by the user manually and the other being automated by the task scheduler.
    When executed by the task scheduler, command line arguments will be used so that the application is aware that it is being run automatically and not by a user.
    My problem is that I want the startup form to load when run by a user but I don't want it to load when it is run automatically, I just want to execute code.
    Is it possible to prevent the startup form from loading by using the commandline arguments from the MyApplication_Startup event?
    Cheers

    Hi Aureuz,
    >>Is it possible to prevent the startup form from loading by using the commandline arguments from the MyApplication_Startup event
    It is impossible to accomplish it in the MyApplication_Startup event, we can use Form.Shown event:
    #Form.Shown Event
    http://msdn.microsoft.com/en-us/library/system.windows.forms.form.shown(v=vs.110).aspx
    If we start a form by using the commandline arguments, the count of CommandLineArgs will be above one, if so, use Me.Hide() method to hide this form.
    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
    Dim args As String() = Environment.GetCommandLineArgs()
    If args.Count > 1 Then
    Me.Hide()
    Else
    Me.Show()
    End If
    End Sub
    You can also uncheck "Enable application framework" on the project properties application tab and select your startup object to a module object:
    Module Module1
    Sub Main()
    Dim args As String() = Environment.GetCommandLineArgs()
    If args.Count > 1 Then
    'Run your background code
    Else
    Dim f As New Form1
    f.ShowDialog()
    End If
    End Sub
    End Module
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Command line arguments with a Labview pda applicatio​n

    Hi Everyone,
    I am in the process of writing some Labview code to run on a PDA that is called from another vendor's software. When called, I need to pass some information to it (in the form of an integer) and then return an error code when it has finished its task (again, as an integer).
    Not being able to compile a my application as a labview dll for to run on a PDA with Windows Mobile 2003, I was hoping to be able to pass command line arguments to my program when compiled as an executable. This doesn't seem to be possible.
    Could someone please confirm that Labview PDA applications do not support command line arguments?
    Any suggestions on how to meet my objective would be most welcome .
    Regards,
    Mark

    Paolo,
    Thanks for your input: storing this information in a text file is a choice we are looking at. But it does leave us with the problem that the vendor's software will not necessarily know when our program has finished running, unless it continuously polls the file to see if there has been any update.
    A dll would be ideal. I was hoping there might be a clever way of emulating this.
    Regards,
    Mark.

  • Read command line arguments with an ActiveX step

    Hi
    I would like to read the command line parameters from TestStand startup. I did find an ActiveX resulting in a Object Reference (See Locals.CommandsRef). How do I use this reference to really get the arguments and their count? See also screenshot.
    Solved!
    Go to Solution.
    Attachments:
    Screenshot.jpg ‏160 KB

    Hi Paulus,
    Via this link, you find an forumthread that describes the same issue. testStand does not support this, but there is a workaround. Attached you find the code.
    The attachment includes a LV vi with the command line. If you doen't use Labview, here is the command line:
    C:\Program Files (x86)\National Instruments\TestStand 2012\Bin\SeqEdit.exe /goto "Parameter1 = test" /runEntryPoint "Test UUTs" D:\Testsequence.seq
    Regards,
    Bas
    Attachments:
    Command line TestStand.zip ‏10 KB

  • Passing command line argument in java

    I was writting a calendar pogram that took user input from the command line. What I want to know is how can I write my program so that if the user doesn't enter the info. it will automatically assign a value to the variable in the array, eg:
    if they typed: java calendarmonth 10 2005
    they would get a printout for the calendar month of October 2005, but I want it so that if they typed
    java calendarmonth 10
    it would automatically assign they year to be the current year, and if they typed
    java calendarmonth
    it would auctomattically assign the current month and year to the program, heres the source code:
    import javax.swing.JOptionPane;
    import java.util.*;
    public class calendarmonth {
         /** Main method */
         public static void main(String argv[]) {
              String monthString = argv[0];
              int month = Integer.parseInt(monthString);
              String yearString = argv[1];
              int year = Integer.parseInt(yearString);
              printMonth(year, month);
              if (month > 12) {
              System.out.println("Invalid Number Please Try");
         //code to perform OK action
              /** Print the calendar for a month in a year */
              static void printMonth(int year, int month) {
                   //Print the heading of the calendar
                   printMonthTitle(year, month);
                   //Print the headings of the calendar
                   printMonthBody(year, month);
              /** Print the month title, e.g., May, 1999 */
              static void printMonthTitle(int year, int month) {
                   System.out.println(" " + getMonthName(month)
                   + " " + year);
                   System.out.println("------------------------------");
                   System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
                   /** Get the English name for the month */
                   static String getMonthName(int month) {
                        String monthName = null;
                        switch (month) {
                             case 1: monthName = "January"; break;
                             case 2: monthName = "February"; break;
                             case 3: monthName = "March"; break;
                             case 4: monthName = "April"; break;
                             case 5: monthName = "May"; break;
                             case 6: monthName = "June"; break;
                             case 7: monthName = "July"; break;
                             case 8: monthName = "August"; break;
                             case 9: monthName = "September"; break;
                             case 10: monthName = "October"; break;
                             case 11: monthName = "November"; break;
                             case 12: monthName = "December"; break;
                        return monthName;
    /** Print month body*/
    static void printMonthBody(int year, int month){
    //Get start day of the week for the first date in the month
    int startDay = getStartDay(year, month);
    //Get number of days in the month
    int numberOfDaysInMonth = getNumberOfDaysInMonth(year, month);
    //Pad space before the first day of the month
    int i = 0;
    for (i = 0; i < startDay; i++)
         System.out.print(" ");
    for (i = 1; i <= numberOfDaysInMonth; i++) {
    if (i < 10)
    System.out.print(" " + i);
    else
    System.out.print(" " + i);
    if ((i + startDay) % 7 == 0)
         System.out.println();
         System.out.println();
    /** Get the start day of the first day in a month */
    static int getStartDay(int year, int month) {
    //Get total number of days since 1/1/1800
    int startDay1800 = 3;
    int totalNumberOfDays = getTotalNumberOfDays(year, month);
    //Return the start day
    return (totalNumberOfDays + startDay1800) % 7;
    /** Get the total number of days since Jan 1, 1800 */
    static int getTotalNumberOfDays(int year, int month) {
    int total = 0;
    // Get the total days from 1800 to year - 1
    for (int i = 1800; i < year; i++)
    if (isLeapYear(i))
    total = total + 366;
    else
    total = total + 365;
    // Add days from Jan to the month prior to the calendar month
    for (int i = 1; i < month; i++)
    total = total + getNumberOfDaysInMonth(year, i);
    return total;
    /** Get the number of days in a month */
    static int getNumberOfDaysInMonth(int year, int month) {
    if (month == 1 || month == 3 || month == 5 || month == 7 ||
    month == 8 || month == 10 || month == 12)
    return 31;
    if (month == 4 || month == 6 || month == 9 || month == 11)
    return 30;
    if (month == 2) return isLeapYear(year) ? 29 : 28;
    return 0; // If month is incorrect
    thanks
    /** Determine if it is a leap year */
    static boolean isLeapYear(int year) {
    return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
    }

    hey smallsouljah , to use code tags just put your code inside code tags.
    to create code tags you just need to press the button code that is located bellow the subject, this will automatically create code tags.
    System.out.println("testing");
    try yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How To Run An External .exe File With Command Line Arguments

    Hiya, could anyone tell me how I can run an external .exe file with command line arguments in Java, and if possible catch any printouts the external .exe file prints to the command line.
    Thanks.

    Using the Runtime.exec() command. And read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Problem associated with Command Line arguments

    hi ,
    I am not able to pass a file path as command line argument in java.
    Actually i want to run a java program from the command prompt passing a file path . Something like this i tried to do , but its not working.
    D:\VISHAL\src> java CopyFile C:\Documents and Settings\Administrator\Desktop\link.txt
    where ,
    CopyFile is the name of my class which i am going to run
    C:\Documents and Settings\Administrator\Desktop\link.txt is the argument.
    Can anyone tell me whether a java program accepts an argument like this, if yes please tell me the exact syntax..
    Thanks
    Vishal J
    Message was edited by:
    vishal_vj

    is there any other way of solving this?Y don't U try it out with the logic as mentioned
    below it wud be the case if U r not going with
    java CopyFile "C:\Documents and
    Settings\Administrator\Desktop\link.txt" 1
    String filepath = new String();
    for(int i = 0; i < Arg.length; i++)
    filepath.append(Arg);
    File f = new File(filepath);
    What????  This is a non-solution to a non-problem.  First of all, you would be constructing a filename without spaces, when the real path contains spaces.  Secondly, even if you did insert spaces it would not matter.  What if the String (and it does not have to be a filename) contained tabs rather than spaces.  The real (and really only) solution to the problem is to put quotes around the argument, for the exact reason stated in my last post.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Command line args from java to C++

    Hi
    I want to pass command line arguemnts argc and argv from java to C++. I have browsed the net and most of them suggested that I declare the jni statement with jObjectarray.
    I saw an example at http://www.csc.calpoly.edu/~fouzi/crossroads/Arguments.c
    It said
    #include "/home/java/linux/jdk118/include/jni.h"
    #include "Arguments.h"
    #include <stdio.h>
    JNIEXPORT void JNICALL
    Java_Arguments_setArgs (JNIEnv *jenv, jobject job, jobjectArray oarr)
    /* obtain the size the the array with a call to the JNI function
    GetArrayLength()                              */
    jsize argc = (*jenv)->GetArrayLength(jenv, oarr);
    /* Declare a char array for argv */
    char const* argv[128];
    int i;
    for (i = 1; i < argc + 1; i++) {
    /* obtain the current object from the object array */
    jobject myObject = (*jenv)->GetObjectArrayElement(jenv, oarr, i-1);
    /* Convert the object just obtained into a String */
    const char str = (jenv)->GetStringUTFChars(jenv,myObject,0);
    /* Build the argv array */
    argv[i] = str;
    /* print the argv array to the screen */
    printf ("argv[%i] = %s\n",i,argv);
    /* Free up memory to prevent memory leaks */
    (*jenv)->ReleaseStringUTFChars(jenv, myObject, str);
    // Increment argc to ajust the difference between Java and C arguments
    argc++;
    // Call a pipeline simulator function which uses command line arguments
    start(argc,argv);
    return;
    That is what I have where the start method is declared like this:
    void start(int argc, /* Argument count */ char argv[] / Argument strings */) {
    But I get a warning when I build the C routine. The warning arises when I am calling the start method.
    The warning says:
    f:\jni\dsaccess.c(711) : warning C4090: 'function' : different 'const' qualifiers
    f:\jni\dsaccess.c(711) : warning C4024: 'start' : different types for formal and actual parameter 2
    Can you help?
    Thanks
    Lakshmi

    1. Your array building looks bogus: Are you missing an index?
    2. You claim to be calling a "method". Are you? Or is it a subroutine?

  • Obtaining command line arguments

    Can someone point me at an example of how to obtain command
    line arguments from inside my Flex application? I want to have my
    Flex application perform different tasks when it is launched with
    different command line arguments, for example:
    myApp.exe 1
    myApp.exe 2
    myApp.exe 3
    How is that done in a Flex app?
    TIA,
    Steve

    "plug_in_guy" <[email protected]> wrote in
    message
    news:gnfgf2$ir1$[email protected]..
    > Can someone point me at an example of how to obtain
    command line arguments
    > from
    > inside my Flex application? I want to have my Flex
    application perform
    > different tasks when it is launched with different
    command line arguments,
    > for
    > example:
    >
    > myApp.exe 1
    > myApp.exe 2
    > myApp.exe 3
    >
    > How is that done in a Flex app?
    This may help:
    http://www.davidtucker.net/2008/01/23/air-tip-7-using-command-line-arguments/

  • Go Online on specific network using command line

    i have a remote troubleshooting software that i wrote myself i have added to it the list of all my clients which can have one of the below:public ipsteamviewer accountslogmein hamachiof course, i'm a paid hamachi client, and i have the latest hamachi version installed whenever i want to troubleshoot any client, i just right click on their name, and select remote desktop.. and the my software will automatically connect to the client using the required authentication/application. when the client has hamachi,his network has to be online, for me to be able to access his ip. so what i'm currently doing is: open hamachi, scroll to my client's network, right click, go online, and then back to my software and troubleshoot! (this is a bit time consuming compared to the other solutions) is there any way, i can go online on a specific network in my local hamachi installation? it would be really a great feature, if we can use a command line script, or use command line arguments to launch special events (locally)example:hamachi.exe /online:mynetworkidhamachi.exe /offline:mynetworkid i appreciate any feedback on this, regards,Dan

    Yes, It would be very interesting to have such a feature.E.g., I need to programmatically request Hamachi to GoOnline, because it often goes offline in some circumstances (after computer wakes from sleep mode for example).

  • Can I convert Word 2003 to PDF using Command Line

    Hello All,
    We have a document generation tool which generates documents in Word 2003 format. The document generation is initiated by the user and the process of generating document is on a remote server. The word file is sent back to the user in word format.
    We would like to convert this doc file to PDF/A format. And we would like to do it programatically, may be using command line arguments. Is it possible?
    Realistically, it is not possible that all the users will have Adobe writer installed in their desktops. In this case, it is possible that Adobe writer is installed in a server and the documents can be converted remotely using command lines?
    Your support on this will be very helpful for us.
    Thanks & Regards
    Irfan

    > Can I use Acrobat Pro to convert a Word 2003 doc to PDF using the Windows command line?
    No.

  • Need Help with command line arguments for a class method

    Hey guys,
    I'm fairly new to programming in java.
    I want to a write a class method that adds up its command line arguments which are numbers. For example, if the input was .... 5 2 3....then the output would be 10.
    I have been told to use the Convert to convert a string to a double. I'm ok for writing the class method but I have no idea how to use Convert and why I need it in the method.
    Can anybody help please?

    Hey guys,
    I'm fairly new to programming in java.
    I want to a write a class method that adds up its
    command line arguments which are numbers. For
    example, if the input was .... 5 2 3....then the
    output would be 10.Okay. So you would receive the numbers to add as the String[] argument to a main method. The steps are simple:
    1) declare a variable for the count
    2) for each String in the array:
    2.1) extract the value as a double
    2.2) add this to the count
    3) output the resulting count
    I have been told to use the Convert to convert a
    string to a double.
    I'm ok for writing the class
    method but I have no idea how to use ConvertThere is no class Convert in the Java API.
    and why
    I need it in the method. Do you understand you need to somehow convert each String to a double (step 2.1)? Since Convert is unknown to me, maybe you should just take a look at class Double. It can help you do step 2.1, the rest should be trivial enough.
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Double.html
    Give it a go and feel free to post back with a specific problem you are having, accurately described if you please :-)

Maybe you are looking for

  • Call Button Greyed Out After A Third Participant Is Added to The Conversation in Office Communicator 2007 R2

    Hi there, I have a problem with the office communicator. I'm able to make a call to one party without any problems. The issue occurs when I add two or more parties into the conversation. The call button will be greyed out and Im unable to make a call

  • What do you do with older versions of Logic?

    I have owned Logic back since Platinum 6, and now i have that version and 6 Pro just sitting around, in their massive boxes with those bible sized reference manuals. I'd like to get rid of them somehow but after checking with ebay, I don't think sell

  • HT1665 can I get a new charger for my iphone

    my iphone stopped charging through the given usb charger and keeps saying cannot sync with this accessory. Is it covered under the warranty?

  • Scedule lines data change after MRP run

    I generates a schedule lines when I run the MRP for certains articles. When I run again MRP, It modifies the data's of schedule line (quantity per ex) even thoough I have already transmetted the request (schedule lines) to the vendor. How to prevent

  • Printing Physical Inventory

    Dear All I am trying to print Physical Inventory Document via MI21.The document is showing correctly all the fields except the counted quantity field.The printout is not populating the quantity even after I do MI i.e. Physical Inventory Count. Can an