07.SpringShell内置命令详解

SpringShell 除了允许我们自定义命令之外, 还提供了一些内置命令, 用于辅助我们操作. 笔者使用的是SpringShell 2.0版本, 内置命令只提供了五个:help, clear, stacktrace, script, exit/quite.

1.help命令-查看帮助

1.1 查看所有内置命令

help 本身就是内置命令, 不跟参数的help命令会打印所有内置命令.

shell:>help
AVAILABLE COMMANDS

Built-In Commands
        clear: Clear the shell screen.
        exit, quit: Exit the shell.
        help: Display help about available commands.
        script: Read and execute commands from a file.
        stacktrace: Display the full stacktrace of the last error.

1.2 查看命令详情

可通过help + 命令方式, 查看命令详情.

shell:>help add
NAME
	add - 计算两个整数的加法
SYNOPSYS
	add [-a] int  [-b] int
OPTIONS
	-a  int
		[Mandatory]
	-b  int
		[Mandatory]
ALSO KNOWN AS
	sum

2. clear命令-清屏

SpringShell 也提供了类似于linux shell的清屏方式, 输入clear 或使用Ctrl+L快捷键.

shell:>clear

3. stacktrace命令-查看异常堆栈信息

默认情况下, 命令执行抛出的异常, 只会输出异常的内容, 不会输出异常的堆栈信息. 当命令发生异常时, 我们可以通过stacktrace 来查看异常的堆栈信息. 需要注意的是, stacktrace 永远只保存上一次的异常的堆栈信息.

shell:>div 2 0
/ by zero
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.

shell:>stacktrace
java.lang.ArithmeticException: / by zero
	at org.zongf.learn.spring.shell.cmd.CalculatorCommands.div(CalculatorCommands.java:32)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:246)
	at org.springframework.shell.Shell.evaluate(Shell.java:169)
	at org.springframework.shell.Shell.run(Shell.java:134)
	at org.springframework.shell.jline.InteractiveShellApplicationRunner.run(InteractiveShellApplicationRunner.java:84)
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804)
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:794)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:324)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at org.zongf.learn.spring.shell.SpringShellApplication.main(SpringShellApplication.java:10)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

4. script命令-执行脚本

script命令使批量执行命令成了可能, 我们可以将一组命令存入文件, 然后批量执行. 需要注意的时, 文件名需要使用绝对路径.

4.1 创建批量脚本文件

脚本存放在 /tmp/zongf/cmds

add 1 2
add 2 3
add 3 4
div 4 2
div 9 3

4.2 执行脚本

shell:>script /tmp/zongf/cmds
3
5
7
2
3

5. exit/quit命令-退出应用

exit和quite命令互为别名, 使用哪个都可以退出应用.

shell:>exit
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值