redirect input standard MATLAB - matlab

From Matlab I call a system command and this command will ask to enter yes or no. How could I redirect to input ?
I've tried:
myCmd = fullfile('control','bin','launch');
cmd = system(myCmd);
=> this will ask following message to enter yes /nos (prompt)
so I've tried
cmd = system([myCmd ,' < ','yes'])
but this is not working.

You can use input function provided in matlab. result = input(prompt) displays the prompt string on the screen, waits for input from the keyboard. More about it here. Hope this helps you.

To request a simple text response that requires no evaluation.
prompt = 'Do you want more? Y/N [Y]: ';
str = input(prompt,'s');
if isempty(str)
str = 'Y';
end

Related

How to catch OS-COMMAND results in Progress-4GL?

I'm using the logging facilities, as described in this other post:
OUTPUT TO VALUE("C:\Temp_Folder\logfile.txt").
...
PUT UNFORMATTED "Start : Check-zones" SKIP.
...
OUTPUT CLOSE.
This is working fine.
Now I would like to add the results of an OS-COMMAND in the output file.
I've already tried the following: (putting the results in a newly to be created file)
OS-COMMAND NO-WAIT VALUE("WMIC printer get name, deviceID >> C:\Temp_Folder\Printers.txt").
This is working fine.
So, I know the command is working fine. However, the following is not working:
OS-COMMAND NO-WAIT VALUE("WMIC printer get name, deviceID >> C:\Temp_Folder\LogFile.txt").
This is obvious, because C:\Temp_Folder\Logfile.txt is locked for writing by the progress application, so the shell, opened by OS-COMMAND can't write to that file.
In order to overcome this, I would like to catch the results of the OS-COMMAND's results.
How can I do this?
Unfortunately back in the dark ages when os-command was designed, it was considered useful to suppress all errors.
You can either start a batch file and let that do some “guaranteed” output error handling, see https://knowledgebase.progress.com/articles/Article/21039
Or (since you are on Windows) you can use the .Net system diagnostics process class (which you will want to wrap in your own method or function to simplify use):
DEFINE VARIABLE oProcess AS System.Diagnostics.Process NO-UNDO.
DEFINE VARIABLE lcstderr AS LONGCHAR NO-UNDO.
DEFINE VARIABLE lcstdout AS LONGCHAR NO-UNDO.
oProcess = NEW System.Diagnostics.Process().
oProcess:StartInfo:FileName = "wmic.exe".
oProcess:StartInfo:Arguments = "printer get name, deviceID".
oProcess:StartInfo:CreateNoWindow = TRUE.
oProcess:StartInfo:UseShellExecute = FALSE.
oProcess:StartInfo:RedirectStandardError = TRUE.
oProcess:StartInfo:RedirectStandardOutput = TRUE.
oProcess:Start().
lcstdout = oProcess:StandardOutput:ReadToEnd().
lcstderr = oProcess:StandardError:ReadToEnd().
oProcess:WaitForExit().
lcstdout = lcstdout + oProcess:StandardOutput:ReadToEnd().
lcstderr = lcstderr + oProcess:StandardError:ReadToEnd().

Qbasic reading comport reply without newline

I'm working on reading device reply using QBasic. The problem is the qbasic wait for the newline or CHR$(13) before outputting the data but my device reply don't have CHR$(13) (example: "OK") so qbasic hang waiting for newline.
How can i get the reply or read comport even without newline? is this possible?
[EDIT]
CLS
OPEN "com2:9600,n,8,1,BIN,cs,ds,rs" FOR RANDOM AS #1
param$ ="Some data"
PRINT #1, param$
DO WHILE b$ <> "*CLOSE*"
INPUT #1, b$
PRINT b$
LOOP
That is my code but in that code it can't read *CLOSE* because no newline after *CLOSE*.
And another thing the device delay 5 sec before replying.
Could you give an example of your code? I suspect you are using INPUT#n , but maybe instead you should use INPUT$(x). I found an example here, see code below
a$ = ""
DO
IF LOC(1) THEN a$ = a$ + INPUT$(1, 1)
LOOP UNTIL INSTR(a$, "OK")
This code sample demonstrates accessing modem in Basic.
REM Reset modem source:
CLS
OPEN "COM2:9600,N,8,1,BIN,CS,DS,RS" FOR RANDOM AS #1
Reset$ = "ATZ" + CHR$(13) + CHR$(10)
PRINT #1, Reset$;
Inp$ = ""
DO
IF LOC(1) THEN
Inp$ = Inp$ + INPUT$(1, 1)
IF INSTR(Inp$, "OK") THEN
PRINT "Modem reset."
EXIT DO
END IF
END IF
LOOP
END

Octave: Problems with load

I'm currently doing a program in Octave where I want the user to be able to insert the file that he wants to load. The files in question are .mat files and are loaded with
load ("filename.mat")
I was thinking about doing something like this:
file=input("Whats the file name: ")
load ("file")
But that didn't work...
Anyone got any tips?
That's likely because you need to input the file name enclosed in single quotation marks : 'filename'. (Note: I use MATLAB but that should work just the same in Octave).
As an alternative you can use inputdlg to request user input. It gives you much flexibility as you can add fields to the prompt such as the file extension or else.
Here is a simple example:
clear
clc
prompt = {'Enter file name'};
dlg_title = 'Input';
num_lines = 1;
def = {'Dummy file'};
answer = inputdlg(prompt,dlg_title,num_lines,def)
The prompt looks like this:
You can fetch the asnwer like so:
name = answer{1};
And finally add the extension to load the .mat file:
filename = strcat(name,'.mat')
S = load(filename)
To do it in one go with the file extension:
prompt = {'Enter file name'; 'Enter file extension'};
dlg_title = 'Input';
num_lines = 1;
def = {'Dummy file'; '.mat'};
answer = inputdlg(prompt,dlg_title,num_lines,def)
name = answer{1};
extension = answer{2};
filename = strcat(name,extension)
S = load(filename)
Hope that helps!
I used Benoit_11's method but changed it to input instead since inputdlg doesn't seem to work in Octave.
clear
clc
name=input('Enter the file name, without the file extension: ','s')
filename = strcat(name,'.mat')
S = load(filename)

Place text from inputbox in a string

I'm looking for a ahk script to do the following:
Show popup box
Enter text
Show standardtext + string in popup box.
So that when for example I press #r i get a popup box, i type in Marc and I get
"dear regards Marc".
So in Java it would be be something like
var1 = inputBox("whats your name")
var NameRegards = function(text){
"dear regards" + var1
}
show NameRegards
Anybody a clue how I can manage this in ahk?
How about doing it exactly as you described?
InputBox, varName, Name input, What's your name?
MsgBox , , Output, Dear regards %varName%
Works fine for me.
Here is an untested start..
#SingleInstance Force
#Persistent
Return ; Stop the startup lines otherwise #r will run on startup...
#r:: ; [Win]+r to start this script
InputBox, MyName, This is your Windows Title, Type your name:
SendInput, Dear regards`, %MyName% ; Using `(On ~ key on US KB) to literally print a comma
; SendInput, % "Dear regards, " MyName ; Alternative way
Return

CATIA macro (Input box not working)

Help My Balloon finding macro is not working with input box, it works only when i manually add the balloon number.. please tell me what i m missing ...Ferdo m expecting you
Language="VBSCRIPT"
Sub CATMain()
Set drawingDocument1 = CATIA.ActiveDocument
Set selection1 = drawingDocument1.Selection
result = InputBox("Ballon Number ?", "Title") 'The variable is assigned the value entered in the InputBox
selection1.Search "CATDrwSearch.DrwBalloon.BalloonPartName_CAP= result ,all"
End Sub
I don't know what you are doing but the last line looks wrong. I don't know what the docs are for your function but you are passing the string result rather than the value of the variable result because it is in quotes. Assuming your line is otherwise right ...
selection1.Search "CATDrwSearch.DrwBalloon.BalloonPartName_CAP= " & result & ",all"