Get JAVA system.out.println in bat?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Get JAVA system.out.println in bat?

#1 Post by mm@muellermario.de » 20 Feb 2015 08:36

Hi everybody,

I wrote a JAVA wich I am calling from a bat.

Code: Select all

java myPackage.MyLitteJAVAPRogramm

The JAVA writes

Code: Select all

system.out.println(myVariable).


How can I access the value of

Code: Select all

myVariable
in my bat?
I can the the value of myVariable in the cmd-Window!!!
But how can I write into a batch-variable?

I am googling for hours; but cannot find a satisfiing hint
Thanky Regards
Mario

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Get JAVA system.out.println in bat?

#2 Post by Squashman » 20 Feb 2015 09:21

If all your program does is write the variable to STDOUT then you should be able to use this.

Code: Select all

@echo off
FOR /F "delims=" %%G in ('java myPackage.MyLitteJAVAPRogramm') DO set myvariable=%%G

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Get JAVA system.out.println in bat?

#3 Post by Squashman » 20 Feb 2015 09:29

mm@muellermario.de wrote:I can the the value of myVariable in the cmd-Window!!!

Forgot to ask.
Can you please perform those tasks in a cmd window and then copy and paste all that output from the cmd window to a response here.
thanks

mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Re: Get JAVA system.out.println in bat?

#4 Post by mm@muellermario.de » 20 Feb 2015 10:51

HI Squashman,

thx for the reply. If you want I can send you all -> The jar-files.

It took me a lot of work. I got one batch to decode passwords. The decoded pw is the output in the cmd window and also set to the clipboard.
The user should than copy the decoded PW in an another bat; called decode.bat

This is the bat that makes me problems. It is calling the decoder.java and should receive the decoded pw. This works fine. I can see the decoded pw in the cmd window. But than I want to use ist to logon on an SAP-System; so I have to pass the decoded PW into a variable.

If it works, this would be a very nice tool.

As I have my coding at work, I will do this on monday.


BTW: Is it possible to attach files here in the forum?

regards
Mario

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Get JAVA system.out.println in bat?

#5 Post by foxidrive » 20 Feb 2015 11:49

Squashman wrote:If all your program does is write the variable to STDOUT then you should be able to use this.

Code: Select all

@echo off
FOR /F "delims=" %%G in ('java myPackage.MyLitteJAVAPRogramm') DO set myvariable=%%G


mm@muellermario.de
Did you try the code above?

Put the word echo before set and try it. What you see on the console?

Add pause as the last line if you are clicking on the batch file.

You can upload the files to dropbox and post the link here - there's no feature to attach them.

mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Re: Get JAVA system.out.println in bat?

#6 Post by mm@muellermario.de » 21 Feb 2015 06:33

hi foxidrive,

not at all. I got the coding at work. at home I only got a mac :| Regards, Mario

mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Re: Get JAVA system.out.println in bat?

#7 Post by mm@muellermario.de » 21 Feb 2015 06:41

hi foxidrive,

I forgot. I uploaded it on google drive. But I need your mailadress. Does dropbox net need a mailadress also?
Regards MM

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Get JAVA system.out.println in bat?

#8 Post by ShadowThief » 21 Feb 2015 08:02

dropbox.com, not .net

And just put the file in the Public folder and click the Share button. You'll get a link that anybody can use to download the file.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Get JAVA system.out.println in bat?

#9 Post by Squashman » 21 Feb 2015 08:39

I do not want the files. I just want to see you execute the program from the command prompt and show the output.

mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Re: Get JAVA system.out.println in bat?

#10 Post by mm@muellermario.de » 21 Feb 2015 09:29

Pls check,

if you can open the link:

https://drive.google.com/folderview?id= ... sp=sharing

Regards, mario

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Get JAVA system.out.println in bat?

#11 Post by ShadowThief » 21 Feb 2015 10:29

The link can be opened fine. We just needed sample output.

Image

mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Re: Get JAVA system.out.println in bat?

#12 Post by mm@muellermario.de » 22 Feb 2015 02:51

Hi ShadowThief,

sorry I donut understand your question.
The screenshot - as you can see- is decrypting the PW <password>
Now I need to enhance the script, that <password> is passed into a variable.

Thats the problem.


Regards
Mario

mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Re: Get JAVA system.out.println in bat?

#13 Post by mm@muellermario.de » 22 Feb 2015 03:05

This might be confusing.
Concerning the screenshot: I saw that the request its wrong:
I has to be

"Bitte das verschlüsselte Password zum Entschlüsseln eingeben"

In english: pls give the encrypted password for decryption.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Get JAVA system.out.println in bat?

#14 Post by ShadowThief » 22 Feb 2015 04:05

I didn't have a question. I was answering a question that was addressed to you.

mm@muellermario.de wrote:This might be confusing.
Concerning the screenshot: I saw that the request its wrong:
I has to be

"Bitte das verschlüsselte Password zum Entschlüsseln eingeben"

In english: pls give the encrypted password for decryption.

I don't see how that's my concern; that's your code, not mine.

Now then, do you need the variable to be the encrypted password or the decrypted password?

mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Re: Get JAVA system.out.println in bat?

#15 Post by mm@muellermario.de » 23 Feb 2015 02:56

Hi ShadowThief,

I am not sure, what is missing now. Could you please see whats wrong in the script?

Code: Select all

@echo off
set CLASSPATH=decoder.jar
FOR /F "delims=" %%G in ('java decode.decoder "dGhpc0lzTXlQVw=="') DO
{ echo set myvariable=%%G
   pause
   echo %G%
   pause

}


The Console-Output is:

Code: Select all

set myvariable=thisIsMyPW
Drücken Sie eine beliebige Taste . . .
ECHO ist ausgeschaltet (OFF).
Drücken Sie eine beliebige Taste . . .


But I cannot see the value of %G%

Thank you much, Regards Mario

Post Reply