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.
Similar Messages
-
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 -
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 :-) -
Executing another program with command line arguments
I am very new to Java, so bare with me.
I have written an encryption/decryption program in C (that accepts command line arguments of the key, mode (encrypt/decrypt), and file), and I have written a GUI for it in Java. It accepts the filename (and has a button which opens the "File/Open" dialog), key, and mode, and has a button to Start the process of the encryption. I'd like for that "Start" button to call my encryption program in C (eep.exe) with the command line arguments of the file, key, and mode. This is what I have written so far :
Start = new JButton("Start");
Start.setBounds(150, 180, 90, 25);
Start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Desktop.open(new File("C:\\eep.exe" + " " + filename + " " + mode + " " + key));
However, I get the error "Cannot make a static reference to the non-static method open(File) from the type Desktop" on the Desktop.open command.
What should I do? Is Desktop.Open the right way to go about this? If not, what is the right way to go about it?
Thanks in advance.That has helped greatly, but I cannot pass command line arguments to it.
Using :
try {
Desktop.getDesktop().open(new File("C:\\eep.exe"));
catch (Exception e) {
System.out.println("Error executing.");
}I can execute eep.exe, but when I try to pass command line arguments to it, such as
Desktop.getDesktop().open(new File("C:\\eep.exe" + " " + filename));it fails, get caught and prints "Error Executing."
I have also tried loading the program, as well as some command line arguments into an array of strings :
String[] cmdArray = {"C:\\eep.exe", filename};
Desktop.getDesktop().open(new File(cmdArray));But it gives me the error "The constructor File(String[]) is undefined" on the
new File (cmdArray)part of the command. -
Launch executable with command line arguments
I have a programmer that I need to launch in my cvi code. I tried the system command and lauchexecutable command but cannot get the programmer to lauch correctly. If I run it from the command prompt or create a windows shortcut it works fine. Here is the shortcut I created:
C:\TPD\SAVS20P3\asix\up\up.exe /e c:\tpd\savs20p3\q33.hex/erase /q /p
I'm trying to run the up.exe software with /e c:\tpd\v20_hex\v20.hex /erase /q /p as the command line paramters.
I tried the following code which created the above path with command line
strcpy(filename,"C:\\tpd\\savs20p3\\asix\\up\\up.exe /e c:\\tpd\\savs20p3\\hex_ee\\"); ///e c:\\tpd\\savs20p3\\hex_ee\\"");
strcat(filename, hfile);//hex file name will change dynamically
strcat(filename, "/q /p");
I then tried LaunchExecutable(filename) and system(filename). The system functions gives an error. Its trying to lauch the /e c:\tpd\v20_hex\v20.hex file
any suggestions. I beieve its a simple syntax error.Well, apart evident typos in the code you posted, which is not creating the command line you stated, I can only think that before "/q" you should add a space to separate the option from the filename.
This code should create the correct command line:
strcpy (hfile, "c:\\tpd\\v20_hex\\v20.hex");
strcpy (filename, "C:\\tpd\\savs20p3\\asix\\up\\up.exe /e ");
strcat (filename, hfile);
strcat (filename, " /erase /q /p");
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
Problem with command line argument files and quoted strings
I'm trying to use the following custom tag:
-tag com.me.Test.testTag:f:"My Test Tag"
This works fine when sent straight to the command line, but if I put it in an argument file (@argfile) along with the rest of my command, I get the following error:
javadoc: Illegal package name: "My Test Tag"
Any idea why this is happening? If I use a one-word tag header and omit the quotes, javadoc runs with no problems. I'm using Sun's SDK 1.4.1.
Thanks for your help!
Linda HowardWhite space is treated a bit differently in an @argfile,
to enable users to put packages or options on separate lines.
You might try escaping the spaces:
"My\ Test\ Tag"
or using a non-breaking space:
"My Test Tag"
What operating system are you on?
-Doug Kramer
javadoc team -
Problem with command line arguments and multiple targets in ant
Based on the argument value,I have to create properties file .I am using the key value pairs present in the properties file in my build.xml file.
Here the problem is , I am able to create the properties file,using the argument vaue.i.e.,
ant -Denv=build-dev copy.
ant build-all.
it works fine,but if i want to call another target which uses the propeties file ,at the time of passing argument is failing
ant -Denv=build-dev copy build-all
why it is happening ?
My build.xml file
<project name="AntParam" default="copy">
<target name="copy">
<fail unless="env">You must specify the env property when you run ant.</fail>
available property="env.prop.file.exists" file="${env}.properties"/>
<fail unless="env.prop.file.exists">Cannot find ${env}.properties file.</fail>
copy file="${env}.properties" tofile="build.properties" overwrite="true"/>
</target>
<target name="build-all">
<property name="one.dir" value="${project.home}/two" />
</target>
</project>
"${project.home}"--------this value I am getting from properties file.i find solution.
-
Writing command line arguments
Is there a way in java to specify which command line argument belongs to each option, like in Perl?
Like -name Sally -age 23 -city New York
Or would one have to write their own parsing function to do that?You see a lot of quick and dirty initialization code that looks likeif (args.equals("-name")) {setName(args[i+1]);}Obviously the getopts people had to write one too many program with command line arguments.
-
We have downloaded and installed the HP Photosmart full feature Sostware and Drivers to Photosmart C3183 All-in-one.
Click the Scan document in Solution Center-
Error message displayed:
The scanning software was launched with improper command-line arguments"
Extended error information: 8,[(-1,0,0)]
When Hp scan diagnostic utility was used - the message was: no scanners installed.
how can we resolve the scanning problem
nidataytayI have the same problem on a HP 5610 Officejet All-in-One.
"The scanning software was launched with improper command-line arguments.
8, [(-1, 0, 0)]"
What is the solution? The scanner does not work. All other functions, print, fax, copy work from with in the HP Solutions Center software - but not the scanner. -
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,
MarkPaolo,
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. -
Help with char and command line arguments
I am writing a program that takes 2 command line arguments (such as 4 b, or 3 4, etc.). It uses the first argument to determine the height of a triangle (how many rows high), and the second is the character with which the triangle is drawn.
My problem is I tend to code backwards - go for the bigger part and then figure out the smaller things. So, I've written a program that prints out this triangle, BUT I can't figure out how to get the command line arguments into it properly. A number works fine because I can:
size = Integer.parseInt(args[0]);
but what do I do if the second argument is a character? Args is a String array (I've been fighting with it for the past 4 hours, so I KNOW its a String array) - so how can I get a char to be read as args[1]?
Here is my code before adding in the second argument (the char):
public class Triangle
public static final void main(String[] args)
int size;
if (args.length > 0)
try
size = Integer.parseInt(args[0]);
catch(NumberFormatException e)
System.out.println("Input Error");
createFilledTriangle(size);
System.out.println();
public static void createFilledTriangle(int size)
int i = 0;
int j = 0;
for(i = size, j = 1; i > 0; i--, j +=2)
printChar(" ", i);
printChar("*", j); <-----Instead of using * I want to use the second command line arg
System.out.println();
private static void printChar(String str, int total)
for(int i = 0, i < total; i++)
if(i%2 == 1)
System.out.print(str);
else
System.out.print(" ");
Thank you for any help in advance!I was sure i send it the other day, i probably send it to the wron guy.
This will give you more idea about drawing.
import java.awt.*;
import java.awt.event.*;
public class Args extends Frame
Panel panel = new Tpan();
int arg1;
char arg2;
public Args(int a1, char a2)
super();
arg1 = a1;
arg2 = a2;
setBounds(1,1,600,400);
setLayout(new BorderLayout());
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent ev)
{ dispose();
System.exit(0);
add("Center",panel);
setVisible(true);
public class Tpan extends Panel
public Tpan()
public void paint(Graphics g)
super.paint(g);
g.setColor(Color.blue);
g.drawLine(120,110-arg1,80,110);
g.drawLine(120,110-arg1,160,110);
g.drawLine(80,110,160,110);
g.setColor(Color.red);
g.drawLine(120,110-arg1,120,110);
g.setColor(Color.black);
g.drawString(""+arg2,116,110-arg1/2+10);
public static void main (String[] args) throws InterruptedException
// get the 2 arguments from the args insread of a1= , a2=
int a1 = 60;
char a2 = 'a';
new Args(a1,a2);
Noah
import java.awt.*;
import java.awt.event.*;
public class Args extends Frame
Panel panel = new Tpan();
int arg1;
char arg2;
public Args(int a1, char a2)
super();
arg1 = a1;
arg2 = a2;
setBounds(1,1,600,400);
setLayout(new BorderLayout());
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent ev)
{ dispose();
System.exit(0);
add("Center",panel);
setVisible(true);
public class Tpan extends Panel
public Tpan()
public void paint(Graphics g)
super.paint(g);
g.setColor(Color.blue);
g.drawLine(120,110-arg1,80,110);
g.drawLine(120,110-arg1,160,110);
g.drawLine(80,110,160,110);
g.setColor(Color.red);
g.drawLine(120,110-arg1,120,110);
g.setColor(Color.black);
g.drawString(""+arg2,116,110-arg1/2+10);
public static void main (String[] args) throws InterruptedException
// get the 2 arguments from the args insread of a1= , a2=
int a1 = 60;
char a2 = 'a';
new Args(a1,a2); -
Command line Argument Problem - '*'
Hi, Is there any problem in giving * as Command line argument.
My student was trying to write a calculator program but stuck :
Code Sample
public class test
public static void main(String[] args)
System.out.println(args[1]);
java test 2 + 2
No Problem
java test 2 * 2
gives ProblemIt's not relevant to the programming language. The shell is what expands the *.
OTOH, I heard that MS-DOS filename expansion is spotty (that's been my experience actually) and that Java has a workaround built into it to make it make sense.
I'd encourage you to change the assignment (or however this is working out) to allow your student to submit the entire expression as a single argument:
java Calculator '2 * (3 + 2)' -
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
EckbertSo, 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 -
ERROR: -1639 INVALID COMMAND LINE ARGUMENT
Trying to install software for Shuffle that Santa brought and get this error messsage...
"Error: -1639 invalid command line argument. Consult the windows Installer SDK for detailed command line help."
Install stops at this point.
SOMEONE HELP... My kid is chomping at the bit !
Thanks.Ok I'll do some more searching but I found something in the community forums.
APPSearch can not return this data into a property, so instead, for some unspeakable reason, returns a value of Null, follwed by another Null. This means that the property is created, and populated with two null characters. Bad news if the property also happens to be a PUBLIC property. All public properties are passed as part of the command line sent in a stream to the background installer process by the Execute Action. Since this stream now contains a double null value in a property, the stream is prematurely terminated. This creates an invalid command line, and thus the 1639 error.
This user solved it by using the MSi Cleanup installer util.
EDIT: A little more info...
This problem is almost impossible to detect through the MSI log files since our friends at Microsoft chose to limit the length of any line in the log. It is impossible to get a dump of the full command line that generates this error.
EDIT2:Note that error 1639 only ocurrs when the install package is run from removable media. When the package is run from local storage, the behavior is far more obtuse. The background install process, failing to receive a complete command line, is forced to run as if there had been no UI session, which in turn causes the APPSearch action to run again as if the install was running in silent mode. This causes re-evaluation of all properties a second time, destroying the feature selections made in the UI session, and also forcing the install to run under user credentials instead of elevated, even though AdminUser, ALLUSERS and Privleged properties are set. This is a very serious error that causes total failure of the installation. -
Solaris 10 command-line argument to /etc/init.d/apache
Does anyone know how to control the command-line argument sent to /etc/init.d/apache that ships with Solaris 10 11/06?
# svcs *\apache\*
shows Solaris is running Apache 1.3 as a legacy service with the FMRI lrc:/etc/rc3_d/S50apache.
According to Sun documenation ("How to Modify a Command-Line Argument for an inetd Controlled Service" <http://docs.sun.com/app/docs/doc/817-1985/6mhm8o5ss?a=view>), one should be able to make desired changes using the inetadm command. The problem is,
# inetadm
doesn't show anything at all related to apache or httpd. I thought about changing the inittab file, but Sun's comments in the file pretty much say "hands off."
I'm trying to have Apache SSL enabled at boot time (i.e. argument startssl instead of start). As a temporary hack, I've edited apachectl so that the "start" argument is processed like "startssl."
Thanks!tmilbank wrote:
Does anyone know how to control the command-line argument sent to /etc/init.d/apache that ships with Solaris 10 11/06?
# svcs *\apache\*
shows Solaris is running Apache 1.3 as a legacy service with the FMRI lrc:/etc/rc3_d/S50apache.
According to Sun documenation ("How to Modify a Command-Line Argument for an inetd Controlled Service" /etc/rc3 services have nothing to do with inetd.
The script is running from the above file (/etc/rc3.d/S50apache).
That's normally apache 1.x. If you do 'svcs -a', you'll see disabled services as well, which will include the apache 2.x server.
<http://docs.sun.com/app/docs/doc/817-1985/6mhm8o5ss?a=view>), one should be able to make desired changes using the inetadm command. The problem is,
Neither version of apache runs from inetd. Are you interested in apache 1.x or apache 2.x?
Darren
Maybe you are looking for
-
Using a File Adapter in a BPEL process
Hi, I am new to BPEL and currently working on migrating my current integration to a SOA architecture using BPEL processes. The integration requires a file to be read and i plan to use a fileadapter . This file to be read is of fixed length type and i
-
It consumes 30% of cpu and takes with it firefox, together consuming more than half of CPU and going on >1/2h. This is a new phenomenon which slows down all other activity on my computer.
-
Hi, Could you help me to find what's wrong in my URL? I was trying to schedule a job to run every Friday. Here is my URL: http://report.iashub.com/dev60cgi/rwcgi60?ias&server=Repserv&report=possessioncnco.rdf&destype=cache&desformat=pdf&schedule=ever
-
Movement Type for GR to Post material in COST center
Hi ... Do I need to use 101 Movement type even to Post Material into consumption... or in simple words if i have account category "K" in Purchase Order then which Movement type I should select to prepare GR and do I need to use same MIGO transaction
-
Need help for "From concatenate string insert to mysql table"
Well, most of this problem is a question about SQL syntax. In the VALUES clause you put a comma delimited list of the values to go into the new record. You insert one record at a time. How are the columns defined? Have you done any study on basic SQL