What is the equivalence of the command "set /p" present in bash, in efi shell? - shell

I need the command that asks the user to write some input and then store it in a variable.
In the terminal I was using the command like this:
set /P SP=Enter the product model:
set /P SS=Enter the serial number:
\SCRIPT\******.exe /SU AUTO /SP %SP% /SS %SS%
But I can't find a similar way to do it with EFI shell commands, there is a set command, but I can't use it in the same way.
I tried with the -v option, but I didn't get the result I expected.
Update : Thanks for your answers.
Yes i think that set /p is a cmd command.
The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty.
the example I took with the SP and SS allows me to ask the input user for a value for example the product name with SP and the serial number with SS, and then I run a script that will allow me to change the SMBIOS values ​​and make it transparent to the user who only needs to enter the values.

There is no native "input" command in EFI Shell, so, in order to deal with this problem, you can try some different approaches:
Create an .efi application, you can use ReadKeyStroke function to get the user input
Create a python script, you will need to have python binary in the same device that EFI shell file is. You can build python following the steps available on edk2 lic repo (https://github.com/tianocore/edk2-libc/tree/master/AppPkg/Applications/Python/Python-3.6.8)
Use .txt file previously filled by the user and explore the command "parse" to get the information and set it as shell variable.

Related

How to "pipe" console values into interactive Windows PowerShell command (to make it non-interactive)

Does Windows PowerShell have anything that's similar to piping user-supplied values into interactive Unix/Linux bash commands to make them run non-interactive?
What I mean is something like this:
https://www.igorkromin.net/index.php/2017/04/12/invoking-interactive-shell-scripts-non-interactively
I need to supply values directly via PowerShell instead of letting the user type them on the console.
What I mean is not something that would be equivalent to xargs in bash, as that would only allow me to supplant command line parameters. For the specific command that I have in mind, default values can be specified on the command line, but are not suitable for the specific task. There are not any other parameters that can be given on the command line - values other than default are normally given by user input.
The only thing I tried out was similar to how you would do it in bash:
echo VALUE | CMD
This didn't work as the command still asked for user input on the console.

Request user input in bash_profile alias command

Is there anyway to stop in a bash_profile alias command and prompt for a user input? I'm fairly new to writing terminal commands.
I'm making a custom command that will take 2 inputs and edit my host files and set up vhosts for me on my local machine, at the moment i'm just passing the arguments into the command
addSite mywebsite.co.uk
But ideally I would like to be able to just run addSite, then the command stops and prompts 'Please enter the domain for your new site'.
Is this possible? If not, can someone point me in the right direction to be able to write a custom terminal command that can do this?
Thanks
You can ask for user input with read and pass a prompt with the -p flag. After the command, you specify the variable name. Then access it like any other variable.
read -p 'Please enter the domain for your new site: ' domain
echo Your domain name: $domain
EDIT: as pointed out by #tripleee in the comments, it's worth noting that this will have unintended side effects if a shell is launched from another source e.g. if you launch an executable file from Finder.

Stata command line arguments in batch mode

A helpful FAQ from Stata describes that arguments can be passed to do files. My do file looks like this:
* program.do : Program to fetch information from main dataset
args inname outname
save `outname', emptyok // file to hold results
insheet using `inname', comma clear names case
// a bunch of processing
save `outname', replace
According to the FAQ, this script can be run using do filename.csv result.dta. When I run this command from within Stata, everything works fine. The program is long, however, so I want to run it in batch mode. Stata has another FAQ about batch mode.
Combining the information from these webpages, I type the following at my Unix prompt:
$ nohup stata -b do program.do filename.csv result.dta &
Stata starts up, but it terminates with the following error:
. save `outname', emptyok // file to hold results
invalid file specification
r(198);
A little experimentation tells me that Stata is never receiving the two arguments when I run the program in batch mode. What is the solution to this problem? (i.e. how do you pass arguments to a do file when running it in batch mode?)
The thread below may be helpful:
http://www.stata.com/statalist/archive/2012-09/msg00609.html
In Windows, if my program Test.do is:
args a b
display "`a'"
display "`b'"
I can run it in batch mode in Windows by simply typing:
"c:\Stata13\stata.exe" /e do "c:\Scripts\Test.do" Test Script
And it will display (within Stata):
Test
Script
So I wonder whether the nohup is what's preventing your program from working.

How to automate application based on command line?

I have a Java based application which I run using command prompt. I am currently testing it manually. I want to automate the process. What tool or scripting should I use?
For example:
First I will run the java command to run the .java file.
My application will give me 5 options. For example
i. Add
ii. Subtract
iii. Multiply
iv. Divide.
It should select one of the options and add the number and verify the result with the expected result. All this will be done using command prompt.
I realize that you're asking for a command prompt solution, but you really should look into JUnit. It will be a much more maintainable solution for a larger variety of test conditions. If you use the command line, you'll have to parse all of the input and output. In order to truly test your code, you shouldn't have to go through the intermediate of the command line (stdin, stdout); you should have Java code that runs your Java code, since it can access the variables.
If you really are set on using the command line, you would have to give us more details on how your program runs. This is just a shot in the dark:
inputs.txt (These are the inputs that will be fed to your program)
Add
4
6
test.bat
#ECHO OFF
:: I just assume that your program prompts for input and waits for stdin
java YourMainClass < inputs.txt > testOutput.txt
:: Program prompts for an operation; "Add" is read from inputs.txt
:: Program prompts for values; "4" and "6" are read from inputs.txt
:: Program prints out the result, which is redirected to testOutput.txt
:: Now you have to read in the testOutput.txt file and look at the last line
FOR /F %%i IN (testOutput.txt) DO SET RESULT=%%i
:: The variable RESULT now contains your program's answer
:: Create a variable to compare your actual result with the expected result
SET EXPECTED=10
IF %RESULT% == %EXPECTED% ECHO "You were correct"
IF NOT %RESULT% == %EXPECTED% ECHO "You were not correct"
You need to use a batch file. Put your commands in a notepad file and save it as .bat.
If they are not native batch commands though you may need to change some things, but you would need to post you commands before I can confirm.
Standard input can be fed into java application. If you're using bash it can be done like the following:
java myapp.java < test1
Where myapp.java is your application with main-method, and test1 being your test input (a plain old textfile).

Send commands to other command-line programs

Is there a way, to send commands to another command-line program?
'Cause i have a special command-line program, but I can't send commands to it using syntax like program.exe something_to_do
the program executes something like this: ("here syntax" is where i want to input text to and also enter to start)
TheWhateverCommandLineProgram
Version 1.1
Give an option: "here syntax"
the program in code looks something like this:
echo TheWhateverCommandLineProgram
echo Version 1.1
Set opt=
set /p opt=Give an option:
if %opt%==command1 goto com1
if %opt%==command2 goto com2
...
Well, i guess so cause it wasnt me who made it (btw: off course its not called TheWhateverCommandLineProgram)
If you just want to give keyboard input to a commandline program you can just use echo and pipe it:
echo some text | program.exe
If you need more lines, then write them to a file and use input redirection:
echo one line > file
echo second line >> file
program.exe < file
I'm not 100% sure I understand what you're looking for. Here's two options:
You have two windows, each running a batch program. Let's say they are called myscript1.bat and myscript2.bat. You want to send a set of commands from myscript1.bat to be executed by myscript2.bat
You have a single batch script named myscript.bat, which executes a single program named program.exe. You want program.exe to execute some commands, or do some something.
Are either of these what you're looking for? Here's some idea:
Make myscript1.bat create a third file, mycommands.bat. Once myscript2.bat sees the file mycommands.bat exists, it will execute it and delete it. (Wow. Lame.)
Use Windows Scripting Host command (it's built in to Windows since Win2K) or Powershell (usually on most computers nowadays, if they have been updated). Either of these can send keystrokes to another program. Using those keystrokes, you can control the other program.
In what form does the other program take input? From the command prompt?
If the latter then I recommend Autohotkey: http://www.autohotkey.com/
You can use Autohotkey as a bridge and it will send the command as keypresses to the window of the other batch file.
You can ask for help in their forum. They are quite helpful.

Resources