In java, how can you use the command line parameter 'ipconfig > ipInfo.txt', and then to save the text file onto you USB key?
Ive tried many ways, but can't get my head around it.
Thanks
Printable View
In java, how can you use the command line parameter 'ipconfig > ipInfo.txt', and then to save the text file onto you USB key?
Ive tried many ways, but can't get my head around it.
Thanks
Are you asking how to read a file and write another file?
Hm not exactly. If you go into command prompt and type in: ipconfig > ipInfo.txt, the output of the command is copied into a created file called 'ipInfo.txt'.
My question is, how can you do that in java? (As far as i know it will be executed from the exec() method from the Runtime class)
Thanks
Yes the Process class and Runtime class can be used to execute a program.
Yeah i know. Ive have a method that reads in an array of commands and executes them.
The sample code is an array of commands that are passed in the method called execCmds(String[] commands).
public static void main(String args[])
{
//List of commands
String[] command = new String[5];
command[0] = "cmd";
command[1] = "/C";
command[2] = "cd";
command[3] = "f:\\Year 3\\Semester 6\\Team Project";
command[4] = "ipconfig > ipInfo.txt";
try
{
//Execute the commands from array
service.execCmds(command);
}
//catch any exceptions
catch(Exception e)
{
//do nothing
}
}
But I get an error while it tried to run:
The filename, directory name, or volume label syntax is incorrect.
----jGRASP wedge2: exit code for process is 0.
----jGRASP: operation complete.
Thanks
Is that error written to the text file by the ipInfo command?Quote:
But I get an error
What are the contents of the command[] array supposed to do?
Why not use another version of the exec() method?
No. The command did not even create the text file at all. I think I have the commands in a wrong order, although in not sure?
Other commands work fine such as 'dir', 'cd', 'ipcinfig' etc. But not these set of commands/
If you want to change the working directory the exec() method has an override to do that.