Start a Spring-Shell based application not interactive - spring-shell

Is it possible to start a specific command of a Spring-Shell app and then return/exit the shell after the command is finished? Further is it possible to expose the exit code (System.exit) of the app to the operating system shell?
For my purpose i will take advantage of the plugin mechanism and the CLI-Annotations of Spring-Shell. But in general there is no human interaction with the app, instead a job scheduler (UC4) will start the app and check the exit code to generate an email in case of an exit code not equal to 0. On the other hand for manual tests by our customer, there is also the need of tab completion, usage help etc.

This behavior is already built-in (although we considered removing it, or at least make it optional). I see now that it is useful :)
Simply invoke the shell with your (sole) command and the shell will spin up, execute the command, and quit. Also, the return code of the shell already indicates whether there was an error or not (tried with an inexistant command for example). Of course, if your custom commands do not properly indicate an error (i.e. print an error message but perform a normal return) this will not work. You should throw an exception instead.

The behavior is back.
Run spring-shell with #my-script, like so:
java -jar my-app.jar #my-script
Where my-script is a file with your commands:
my-command1 arg1 arg2
my-command2 arg1 arg2

Related

Execute Unidata Process from the shell command lines?

Is it possible to execute the Unidata process from the Unix Command line??
If it's possible, can anyone please let me know how to??
I just want to add some Unidata Processes into the shell script and run it from the Unix
Cron job.
Unidata Process
Unix Command line
Yes! There are several approaches, depending on how your application is setup.
Just pipe the input to the udt process and let 'er rip
$cd /path/to/account
$echo "COUNT VOC" | udt
This will run synchronously, and you may have to also respond to any prompts your application puts up, unless it is checking to see if the session is connected to a tty. Check the LOGIN paragraph in VOC to see what runs at startup.
Same, but run async as a phantom
$cd /path/to/account
$udt PHANTOM COUNT VOC
This will return immediately, the commands will run in the background. Have to check the COMO/PH file for the output from the command. It's common for applications to skip or have a cut down startup process when run as a phantom (check for #USERTYPE)
If none of the above work because of the way your application is written, use something like expect to force the issue.
spawn udt
expect "ogin:"
send "rubbleb\r"
etc.
https://en.wikipedia.org/wiki/Expect for more info on expect

Execute a personal trace32 function when line is reached during test

I'm testing a real-time application on physical hardware via lauterbach-trace32 probe.
Trace32 documentation is too vast and very technical but I'm not able to find how to implement what I need. I would like to know if there is a method to execute a trace32 function every time a specific code line (under test) is reached in program execution.
What I need is something similar to trigger in database scenario, where an automatic event is raised every time a specific condition is satisfied.
Thank you all!
You can always set a breakpoint, which executes a PRACTICE command every time the breakpoints gets hit. E.g.
Break.Set myFunc /CMD "PRINT ""Hello World""" /RESUME
So this will stop your target CPU when functions myFunc() is reached. Then the PRACTICE command PRINT "Hello World" gets executed and finally your target CPU continues execution (thanks to the option /RESUME). (Consider that double quotes escape double quotes in strings)
Instead of a single command you can also execute more commands (by using option /CMD several times) or execute a PRACTICE script.
If you want to trigger debugger actions on a specific code line without stopping the CPU on that code line, you would need a real-time-trace with external trace interface. So e.g. you would need an ARM CPU with Embedded Trace Macro-cell (ETM) or a PowerPC with Nexus interface. Furthermore you would need Lauterbach hardware for trace-recording e.g. a PowerTrace, CombiProbe or uTrace.
If you have a real-time-trace you can set a "trigger-point" on the specific code line and a execute a command when the "trigger-point" triggers. It looks almost the same way than with breakpoints:
Break.Set myFunc /TraceTrigger /CMD "PRINT ""Hello World""" /RESUME
So the only difference is the option "/TraceTrigger". Of course you should ensure that the real-time-trace is actually working with your setup.

Run shell command step by step

I am vb.net user.
Please some one help me!
How to run shell command in step by step.
When runing shell command in projects,the projects run all command the same time.
Cann't run step by step.
Thanks....,Sorry for Spelling.
If you're using Interaction class' Shell function, the 3rd parameter in it is boolean Wait. Set it to True - and each Shell statement will wait for completion of the command before invoking the next one.
As far as I remember, Shell doesn't wait for child subprocesses, so if you start a process which starts another one and then exits (e.g. bat file without call or with start) - you might face some issues. In this case consider changing the complete tree of calls. Another option would be to use System.Management assembly to trace cals tree using WMI as described here.

Cancel command in Grunt that hasn't been launched

In Pig Grunt, if I make a mistake in my command (for instance not closing a '), it shows a new prompt until the command is fixed:
grunt> tmp = LOAD '/mapred/data;
>>
In the case above, adding '; would solve it, but sometimes the command is long and complex, and finding the culprit proves difficult.
Is there a way to cancel the current entry without exiting Pig altogether? I.e., not ctrl+C or ctrl+D?
Note: I know it's similar to this question how to cancel command in GRUNT shell, but in my case the command hasn't been launched yet.
Corresponding to your example, I realized one way of exiting is to complete the line which is open due to the single quote. Therefore in this case I added the following in the next line and it quit with an error.
>> ';
Not sure if there is an easier way to do this, more so because the grunt shell is still not very developed. In any case, I hope there is a better workaround for this soon.

FORTRAN self-launching MPI program

Is there any way to call mprirun inside FORTRAN program? I'm working on public linux cluster via ssh and the main idea is to automatically enqueue program after its execution is over.
I tried to write something like this at the end of the program:
CALL system('mpirun -np 16 -maxtime 100 TestNP')
But recieved this error:
sh: mpirun: command not found
Any ideas ?
The problem is the missing path prefix, so specifying an absolute path for mpirun should help. However there are several problems with your approach:
If every MPI process executes it, you would have too many instances running, so only one of the nodes (e.g. the master node) should execute it.
The original program won't be finished, until the one called via the system() call did not finish. So, if your queue is wall-clock limited, you don't gain anything at all.
Typically, tasks like this are done via shell-scripts. E.g. in Bash you would write something like:
while true; do
mpirun your_program
done
This would re-invoke mpirun continuously until not killed by you or the queuing system. (So be careful with it!)