Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Logout

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to run from the command line, but have it executed from a jar file. Then I will just put the file on my desktop, and be able to click it to log out.

And yes, I realize I could just make a batch file, but I would like to know how to execute it from java. I have not been able to use the following:


but if someone could post some code, that would be great! Thanks in advance!
 
Ranch Hand
Posts: 73
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have not been able to use the following:
view plaincopy to clipboardprint?
Process process = Runtime.getRuntime().exec(commandLine);



Could you tell what problem you are facing while doing this.
 
Marshal
Posts: 73735
332
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never go anywhere near Runtime.exec() until you have read about the ProcessBuilder class and (more important) the classic paper by Michael Daconta When Runtime.exec() won't.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Len Padson wrote:Then I will just put the file on my desktop, and be able to click it to log out...


Would you? In Windows perhaps, but then Gatesware allows all sorts of odd stuff. I'd be surprised if you could do it in Unix - or at least you might get some rather odd behaviour.

Winston
 
Marshal
Posts: 22385
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Unix it's not that hard to execute reboot, poweroff, halt or shutdown (with or without any arguments). You do need rights to execute those though.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:In Unix it's not that hard to execute reboot, poweroff, halt or shutdown (with or without any arguments). You do need rights to execute those though.


I was wondering more what a spawned process to do a logout would actually do. If you execed it, no problem; but then most icons in Unix don't do that (although maybe it's an option these days).

Winston
 
Len Padson
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, could i create a batch file containing "logout -l" and then just launch that file from my java program? I do not know if it is possible to open a file from java...
 
Campbell Ritchie
Marshal
Posts: 73735
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try passing “logout.bat” or “logout.sh” as a parameter to Runtime.exec().
I have never tried, so I don’t know whether it will work.
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic