Automating user inputs to an INTERACTIVE Ruby console - ruby

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?

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.

Related

ITerm: Is there a way to reprint output of previous command without running it?

Of course, we can feed the output of any command to a file. Using command > /tmp/filename
Or even better use command | tee /tmp/filename to have the standard output be fed onto the terminal as well as the file name.
However, If I just executed command is there a way for ITerm to reprint the output that command already fed to console without re-running the command (example use case: command is not idempotent and I want to grep something without having to touch the mouse)
You could use the script command, which records your input + the output your commands generate.
To use it, just run script at the beginning, before you start any execution, and this will throw you in a new shell. which gets recorded in a file called typescript in your HOME folder.
Once you are done, you can exit, and then have all of the input + output in that typescript log file.

simulate keyboard input to batch file via file and pipe on windows

the title might be slightly confusing but what I need is a method to hand over pre-configured parameters to a batchfile on windows commandline.
The batchflie executes several progams (openssl) that need interactive input. To avoid this, I wrote all necessary input parameters to a textflie and now try to do something like:
type parameters.txt | mybatchfile.bat
Unfortunately this doesn't work.
Is there a way to do this?
Passing text into stdin of interactive prompts of console programs sometimes works, but needs to be done on single line of specific program. Tested way for SSH communication in batch file:
some batch code
echo n| plink.exe -pw "somepassword" root#somehost someremotecommand
some batch code
https://the.earth.li/~sgtatham/putty/latest/w32/plink.exe

How to get output redirect as parameter in bash?

I would like to know if it's possible to get the output redirection file name as a parameter in bash?
For example :
./myscript.sh parameter1 > outputfile
Is there a way to get "outputfile" as a parameter like $2? In my script I have to do few operations in outputfile but I don't know which file I have to update... The second problem is, this script is already running and used by several tasks so I cannot change the user input...
Best regards
Redirections are not parameters to the program. When a program's output is redirected, the shell opens the file and connects file descriptor 2 to it before running the program. The program then simply writes to fd 2 (aka stdout) and it goes to the file.
On Linux and similar systems you can use /dev/stdout, which is a symbolic link to the process's stdout file.

How do I print Selenium Webdriver (Ruby binding) test results to a notepad file from command?

I wish to put the text from command prompt into a text file once the test is run. How do we do that
?
Just use a pipe >. Worth to look Using command redirection operators.
ruby test.rb > file.txt
Redirection operator and description
> : Writes the command output to a file or a device, such as a printer, instead of the Command Prompt window.
< : Reads the command input from a file, instead of reading input from the keyboard.
>> : Appends the command output to the end of a file without deleting the information that is already in the file.
>& : Writes the output from one handle to the input of another handle.
<& : Reads the input from one handle and writes it to the output of another handle.
| : Reads the output from one command and writes it to the input of another command. Also known as a pipe.

Use parameter as intermediate input in Batch File

In a batch file, I am running exe which takes input from user. I want to hardcode value and continue process. check following example:
In Bat File(GetData.bat):
set /p UserInput = Enter a number?
%1
To call bat file:
GetData 5
but it's waiting for input instead of setting 5.
Note: It's just for example actually i am calling exe which takes input in process. I can't modify exe.
Command line parameters are not the same thing as standard input (stdin). There are some programs that can accept input both as command arugments or via stdin, but that is not the norm.
To get your batch script to work, you must ECHO the data to stdout, and then pipe the results to GetData.bat
echo 5|GetData
If you must provide multiple lines of input, then you can do something like
(
echo line1
echo line2
echo line3 etc.
) | yourProgram.exe
Or you can put the input in a text file and then pipe the contents of the file to your command.
type commands.txt | yourProgram.exe
Or you can redirect the input to your file
<commands.txt yourProgram
Note that some programs read the keyboard directly, and or flush the input buffer before prompting for input. You will not be able to pipe input into such a program.
Update - exe not using piped input
Most database command line programs that I have seen have an option to specify the username and password as command line arguments. You should read the documentation, or google your exe for command line arguments.
If your exe does not have an option to specify the values on the command line, then your only option is to use a 3rd party tool like AutoHotKey that can be scripted to pass keystrokes to a running program.
Look at this example:
echo Enter a number?
set UserInput=%1
echo %UserInput%
Then if you type "GetData 5", the output will look like this:
Enter a number?
--empty line to execute "set"
5

Resources