• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble Using Command Line Parameters with Runtime

 
Kris Gates
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kris Gates
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic