1

There is a Ruby file called ABC (for eg). Now this file is called from a Batch file called Batch.bat.

So I would run the Batch file like this:

Batch.bat ip username password.

Now the process goes to Ruby console and provides output as a file system:

0 /
1 10.160.165.86/

Now User must provide inputs as:

10.160.165.86/Computers/Data 

so it move to that location and run one more command :

[Eg: O/P]:   10.160.165.86/Computers/Data > some_command 

Is there a way to automate the user input process using Batch script or using Process Class in Java?

Vic Seedoubleyew
  • 9,888
  • 6
  • 55
  • 76
superuser33333
  • 113
  • 1
  • 11

1 Answers1

0

as another batch script :

echo my_url | Batch.bat

This will pipe the result of echo into the input of your batch file.

Replace my_url by the input you want.

If what you want to input depends on what is outputted by the script, you can also capture its output using a similar redirection, process it, and echo the processed value to it.

Vic Seedoubleyew
  • 9,888
  • 6
  • 55
  • 76
  • I tried using it, since this bat file internally calls the ruby file it is always prompting for user input. – superuser33333 Aug 27 '16 at 09:30
  • normally it shouldn't matter, because the ruby file will read its input from the input of the batch file. What is the line in the batch file that calls the ruby file ? – Vic Seedoubleyew Aug 27 '16 at 09:33
  • All the paths are pushed using **pushd** and then poped using **popd** So then it calls: bin\rubyfile %args% – superuser33333 Aug 27 '16 at 09:43
  • so then it should work. in any case, it will prompt for user input, meaning that you will see it asking, but normally it will instantly read it from what you have supplied in the pipe. are you able to modify the ruby file to test ? – Vic Seedoubleyew Aug 27 '16 at 09:46
  • Yes I can modify it. – superuser33333 Aug 27 '16 at 09:47
  • maybe you could try printing out what it reads as input, to see if it correctly receives it – Vic Seedoubleyew Aug 27 '16 at 09:48
  • But if it worked then when i give a command as echo cd 10.160.165.86 | Batch.bat it should have moved to 10.160.165.86 > directory. But it is still in the basic directory. – superuser33333 Aug 27 '16 at 11:05
  • I think you are confusing passing it am input, which is just a string of characters, and instructing him to do something. "Echo cd /" doesn't change the working directory. It just prints the characters "cd /". If this out put is piped into the input of another script, it is up to he other script to do whatever it wants with it. In any case, even if the other script changes working directory, you wouldn't be able to see it from outside. – Vic Seedoubleyew Aug 27 '16 at 11:19
  • When I run the batch file manually and give **exit** it exits the console.But when I gave **echo exit | Batch.bat**,its not exiting. It means that its not working right? – superuser33333 Aug 27 '16 at 11:33
  • Try just making the batch file read user input and simply re-outputting it, and test what happens when you pipe an echo into it. It seems that here you need to understand what your batch file is doing, as well as your ruby file. It would be good to add their contents in the question if you want me to take a look at them. – Vic Seedoubleyew Aug 27 '16 at 12:04