CMD, REXX, need a way to detect an error - command

I'm very very new to programming/coding.
And I have a very specific question, which I didn't find any answers to.
This command below executes perfectly fine if the command is valid.
If I enter an invalid command, an error occurs and the cmd exits.
enter image description here
But how do I make it, if an error happens, the program starts from the beginning rather than the cmd window closes?
So, in short, I want "SIGNAL start" to happen if an error occurs.
I hope you understand, thank you very much.
other:
SAY "Enter your own command:"
PULL command
command
IF command=ERROR THEN DO
SIGNAL start

It would be helpful if you published all of your code but it seems that what you really need to do is code a loop.
/* REXX */
do forever
say "Enter a command"
pull command
"where" word(command,1)
if rc <> 0 then iterate
command
end

Related

Cannot press any key to continue with command pause

I wrote a script to remote execute test.cmd file by PsExec.exe.
PsExec.exe \\IP -u administrator -p password "C:\\Users\Administrator\Desktop\test.cmd"
Although I can run the script successfully, I cannot press any key to continue the process when it runs into command pause.
Press any key to continue . . . aaaaaa
The only way to keep going is press Enter.
Besides, if there are many lines of Pause or set /p which waits users to input, once user press Enter, it will affect couple lines of Pause or set /p. It really confuses me.
Best is that you use different logic in accordance with your limitations.
Try exchanging the Pause with a different suitable solution.
Other suggestion would be that you share your code, inputs and expectations (output is already given - the script doesn’t continue). Then someone can review the code and suggest for further steps.
Alternatively, it is also possible that you can fix it by using Console.ReadKey()

Show Line Number in Error Message

On most instances of MATLAB I've used, whenever I had a bug in my code the error message in the command window would show the line number.
However on the computer I am currently using, it shows me only the following:
??? Subscripted assignment dimension mismatch.
Is there anyway to get the line number to show again instead of ?????
What you are doing is using Run Section or Run and Advance as #canzar said. If you run scripts like this there is no 'line number', just as when you copy-paste code and run it in the command-window will not show you the line number on the error.
If you run the script using run or by pressing F5 it does know the line number and then prints that on the error statement. Good to know for debugging is to go to the tab editor->breakpoints->dbstop on error. If you press that it will keep your variables as present when the memory occurs, as opposed to throwing everything out when debugging functions.

Appcmd command not working

appcmd set config /section:applicationPools /[name='xxx - yyy'].processModel.idleTimeout:0.00:00:00
When I run this command, instead of receiving a validation message or an error message, the command goes "idle".
It actually just display the caret and I can write text, or wathever... until I CTRL+Break the command.
I tried waiting for 10 minutes but nothing else ever happens.
It's really weird, the command seems correct :S
Do you know what I possibly could be doing wrong?
Apparently when there is a space in the application pool's name, you have to put the "modification parameters" in quote.
So the command should actually be like this:
appcmd set config /section:applicationPools "/[name='xxx - yyy'].processModel.idleTimeout:0.00:00:00"
It really gets me to wonder why the simple quotes aren't useful enough.

Execution of an external program in MATLAB - succeeds only when using &(ampersand), but then does not wait for completion

I am attempting to execute an external program from Matlab:
cmdstr = sprintf('"%s\\myEXECUTABLE" "%s" -options',fullEXEpath, fullInputFilePath);
[status, res] = system(cmdstr);
I receive "status = 1", partial program output in "res" (though no error message) and no output files.
BUT, executing exactly the same command with & (ampersand):
cmdstr = sprintf('"%s\\myEXECUTABLE" "%s" -options &',fullEXEpath, fullInputFilePath);
[status, res] = system(cmdstr);
Meaning in the background via a dos command window, works just fine (status equals 0 and output files are created).
I have seen somewhere it might be that the antivirus is blocking the program from executing via Matlab, but I cannot disable it since I am an endpoint user.
Using "&" causes my GUI to open a command window and run in the background, while immediately resuming Matlab code.
I can live with the command window opening, but not with Matlab resuming right away, as I use the output files in my MATLAB code, which are not necessarily ready.
Is there a way to verify the external program has ended?
I tried simply:
while (status) %waiting for system to return status = 0
disp 'waiting...';
end
but it seems to still return with "status = 0" before completion...
Or rather - is there a way to avoid the &?
Any answer will be much appreciated.
as a debugging method, you can use
system(cmdstr,'-echo')
Since the error messages have nowhere to go, you wouldn't see them. (matlab only returns the output, which might not contain the error stream)
Am I correct you are calling a GUI program with that command? According to the matlab documentation:
The ampersand, &, character has special meaning. For console programs
this causes the console to open. Omitting this character causes
console programs to run iconically. For GUI programs, appending this
character causes the application to run in the background. MATLAB
continues processing.
So console programs (headless programs) would not allow Matlab to continue while executing.

Matlab-like command history retrieval in unix command line

In Matlab, there is a very nice feature that I like. Suppose I typed the command very-long-command and then a few several commands afterwards. Then later if I need the long command again, I just type very and press the up arrow key, my long command appears. It finds the last command that starts with very. I couldn't do the same in unix command line, when I try to do it, it disregards whatever I typed, and goes back to the last commands in chronological order. Is there a way to do it?
In bash this functionality is provided by the commands history-search-forward and history-search-backward, which by default are not bound to any keys (see here). If you run
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
it will make up-arrow and down-arrow search backward and forward through the history for the string of characters between the start of the current line and the point. See also this related Stack Overflow question.
In bash, hitting ctrl-r will let you do a history search:
$ echo 'something very long'
something very long
$ # blah
$ # many commands later...
(reverse-i-search)`ec': echo 'something very long'
In the above snippet, I hit ctrl-r on the next line after # many commands later..., and then typed ec which brought me back to the echo command. At that point hitting Enter will execute the command.
You can do the same thing by using "!". For example:
$ echo "Hello"
Hello
$ !echo
echo "Hello"
Hello
However, it is generally a bad idea to do this sort of thing (what if the last command did something destructive?). If you expect you will reuse something, then I suggest you create a shell script and save it away somewhere (whenever I plan to reuse something, I create a script in ~/.local/bin).