passing variables as arguments in java

Posted on 2006-05-07
Last Modified: 2010-03-31
hi.. a number, 500, is being passed as an argument as shown:

p = r.exec(new String[] {"cmd.exe", "/k", "start", "c:\\a\\test.exe", "500"}, null, new File("c:/a"));

can this number be defined as int number and be passed as an argument....  thanks
Question by:bde521
    LVL 92

    Expert Comment

    no, not really. command arguments are always strings.

    If you want to use a int var then you could do this:

    int n = 500;
    p = r.exec(new String[] {"cmd.exe", "/k", "start", "c:\\a\\test.exe", Integer.toString(n)}, null, new File("c:/a"));

    Author Comment

    objects.... it works...
    one question i may need to pass more than one.... could i just add it to Integer.toString as:
    int n = 500;
    int x = 120;
    p = r.exec(new String[] {"cmd.exe", "/k", "start", "c:\\a\\test.exe", Integer.toString(n, x)}, null, new File("c:/a"));
    thanks ....
    LVL 92

    Accepted Solution

    depends how it is expecting the vars, if its expecting two numbers then try:

    p = r.exec(new String[] {"cmd.exe", "/k", "start", "c:\\a\\test.exe", Integer.toString(n), Integer.toString(x)}, null, new File("c:/a"));

    Author Comment

    objects.. thanks.. bde

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    Title # Comments Views Activity
    method argument as final 1 54
    hasOne  challenge 59 64
    copyEndy  challenge 15 39
    Performance issue while iterating with streams 5 34
    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    This video teaches viewers about errors in exception handling.
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now