aspose file tools*
The moose likes Beginning Java and the fly likes Trouble Using Command Line Parameters with Runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble Using Command Line Parameters with Runtime" Watch "Trouble Using Command Line Parameters with Runtime" New topic
Author

Trouble Using Command Line Parameters with Runtime

Kris Gates
Greenhorn

Joined: Oct 02, 2008
Posts: 2
Hey guys. Been lurking the forums for some time, and as a non-programmer am teaching myself Java out of curiosity and (at least potentially) career thoughts if I like it. Been at it in my spare time for about two months now, finished Head First Java, about 1/3rd of the Sun Java Tutorial, and am waiting on Thinking in Java 4th Ed to arrive at my library. So in short, I am new, I suck, but I appreciate any assistance, and have loved browsing the forum.

At work I am constantly having to disconnect & reconnect my VPN client. Even though a Windows shortcut would do the same thing, out of practice I am trying to build a basic GUI that gives me buttons & hotkeys to connect/disconnect it more easily.

The command line to launch the VPN client & connect is:

"C:\Program Files\AT&T Global Network Client\NetClient.exe -connect -login=password"

Typing this in either the Windows XP Run box, or on the command line, starts up the client and connects to the network.

Unfortunately, I can't get my Java program to do the same thing, and am pulling my hair out.

Here is my code:



This launches my VPN client window, but does not connect it. I have tried a couple variations:







And each time my VPN client launches but does not connect, despite the same lines appearing to work in the Run box.

Am I formatting the command line arguments incorrectly in my code somehow? Is my VPN Client somehow knowing this is machine generated code and not allowing it to connect? Or am I just doing something dense?

Been at this all my free time today... halp!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi,

Welcome to JavaRanch!

At first glance, I'd think it'd ought to work, but Windows command-line processing is a funky thing. I would try the other exec() method that takes an array of Strings:



That way it's you, rather than the NetClient program, that splits up the command line.


[Jess in Action][AskingGoodQuestions]
Kris Gates
Greenhorn

Joined: Oct 02, 2008
Posts: 2
Pow! This worked perfectly - well, ok, the client tried to connect and gave me an error, but progress!

So when you enter a command line in one block, it's treated differently than passing it through as separate strings? Greek to me. On to the next problem. Thanks kindly for the assistance.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

A single monolithic command line has to get broken up into arguments somewhere. On Windows, it's actually up to the individual program to do that -- usually it's the "C" runtime library that does it. Because of this, command-line parsing on Windows is quirky and sometimes painful. Every program can do it differently!

On a real operating system (UNIX-alike) it's the shell that does this; that way it's done uniformly for all programs, and it's a lot more predicatable.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Visual Basic is one of the worst. It just passes everything as one single String. It's up to the programmer to split it properly.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: Trouble Using Command Line Parameters with Runtime