项目中有时需要在Java类中启动一个长时间运行的服务进程(监听进程、监控进程等),且该进程需要在tomcat启动时启动,在tomcat停止时退出。在项目开发的过程中,我需要在Java类中启动一个监听进程,而在该进程成功启动后,一调用该监听服务进程时,该进程就挂掉(退出),现将解决方法记录如下。

Continue reading

本文记录的是如何在Java类中调用外部可执行脚本,例如shell脚本、Python脚本、ruby脚本等。文中阐述了Runtime.exec和ProcessBuilder.start两种调用脚本的方式,官方推荐使用后者的方式,下面对其分别讲述。

Continue reading

本文记录的是shell之printf格式化输出.

首先看看其 man page 内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
NAME
printf -- formatted output

SYNOPSIS
printf format [arguments ...]

DESCRIPTION
The printf utility formats and prints its arguments, after
the first, under control of the format. The format is a character string which contains three types of objects: plain characters,
which are simply copied to standard output, character escape
sequences which are converted and copied to the standard
output, and format specifications, each of which causes printing
of the next successive argument.

The arguments after the first are treated as strings if the
corresponding format is either c, b or s;otherwise it is evaluated
as a C constant, with the following extensions:

o A leading plus or minus sign is allowed.
o If the leading character is a single or double quote, the value is the ASCII code of the next character.

从上述 man page 内容可以看出:

  1. printf通过format字符串格式化输出其后的arguments
  2. format字符串包含三种类型对象: 普通字符串,该对象输出时会直接拷贝到标准输出STDOUT;字符转义序列,通过字符转义之后输出到标准输出;格式说明符,每一个格式说明符对应输出相应的argument
  3. 如果对应的格式指示符是%c/%b/%s时,相对应的参数都视为字符串,否则它们会被解释为C语言的数字常量: 在其开头可使用正负号标识;如果字符串开头是单引号'或者双引号",那么打印输出的值是紧跟着单引号或者双引号后的那个字符的ASCII
Continue reading

本文记录的是关于shell之echo的知识。

echo是linux中常用的终端命令(command line),其包括:

1
command_name option argument

首先看看echo的 man page:

1
2
3
4
5
6
7
8
9
NAME
echo -- write arguments to the standard output

SYNOPSIS
echo [-n] [string ...]

DESCRIPTION
The echo utility writes any specified operands, separated by single blank (' ') characters and followed
by a newline (`\n') character, to the standard output.

从帮助文档可以看出:

  1. echo是将其后的arguments输出到(STDOUT),通常就是bash界面.
  2. echo是将所有的操作对象,以单一的空格` `分开的字符串,最后紧跟着换行符(''),输出到bash
Continue reading

Linux下,如果想要删除目录及其子目录下某种类型文件,比如说所有的txt文件,则可以使用下面的命令:

find . -name "*.txt" -type f -print -exec rm -rf {} \;

. : 表示在当前目录下

-name "*.txt"

表示查找所有后缀为txt的文件

-type f

表示文件类型为一般正规文件

-print

表示将查询结果打印到屏幕上

-exec command

command为其他命令,-exec后可再接其他的命令来处理查找到的结果,上式中,{}表示”由find命令查找到的结果“,如上所示,find所查找到的结果放置到{}位置,-exec一直到\;是关键字,表示find额外命令的开始-exec到结束\;,这中间的就是find命令的额外命令,上式中就是 rm -rf

Comment and share

  • page 1 of 1
Author's picture

CaryaLiu

@Chengdu


iOS Developer


Chengdu