我正在尝试使用read在脚本内执行命令,当用户使用Ctrl+时C,我想停止执行命令,但不要退出脚本.像这样的东西:
#!/bin/bash
input=$1
while [ "$input" != finish ]
do
read -t 10 input
trap 'continue' 2
bash -c "$input"
done
unset input
Run Code Online (Sandbox Code Playgroud)
当用户使用Ctrl+时C,我希望它继续读取输入并执行其他命令.问题是当我使用如下命令时:
while (true) do echo "Hello!"; done;
Run Code Online (Sandbox Code Playgroud)
键入Ctrl+ C一次后它不起作用,但是一旦输入数次,它就会起作用.
我试图在C中运行inotify的例子但是它不起作用.我想监视对文件的修改(文件是tmp.cfg),但它不起作用..我不知道我是否正确运行它,因为我了解如何监视目录,但不是一个file这是一个例子:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/inotify.h>
#include <unistd.h>
#define EVENT_SIZE ( sizeof (struct inotify_event) )
#define BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
int main( int argc, char **argv )
{
int length, i = 0;
int fd;
int wd;
char buffer[BUF_LEN];
fd = inotify_init();
if ( fd < 0 ) {
perror( "inotify_init" );
}
wd = inotify_add_watch( fd, "/home/name/tmp.cfg",
IN_MODIFY | IN_CREATE | IN_DELETE );
length = read( fd, buffer, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 inotify 来监视文件是否在无限循环中被修改。我遇到了一些问题:
1)我有一段时间(1),并且读取不起作用,除非我为该时间的每次迭代创建一个新的文件描述符和一个新的监视描述符(我想做的是在无限循环之前打开这些描述符,但如果其他解决方案可以接受,那么我可以使用它)。这是有效的版本:
while(1){
int file_descriptor = inotify_init();
if (file_descriptor < 0) {
perror("inotify_init");
}
int watch_descriptor = inotify_add_watch(file_descriptor, "/home/user/hello.cfg", IN_CLOSE_WRITE);
....
Run Code Online (Sandbox Code Playgroud)
2)我尝试使用掩码 IN_MODIFY,但我读到它在 vim 中不能很好地工作,所以我使用 IN_CLOSE_WRITE。问题是,当我用vim修改文件时,事件被读取,但事件的掩码是IN_IGNORED(掩码0x00008000)。当我使用gedit时,有时事件的掩码是IN_IGNORED,有时是IN_CLOSE_WRITE(掩码0x0000008)。我想知道为什么我在修改文件时会收到 IN_IGNORED,以及为什么该事件不是 IN_CLOSE_WRITE。还有其他方法可以监视单个文件的修改吗?IN_CLOSE_WRITE 是正确的掩码吗?
我正在使用Eclipse Indigo,我安装了m2eclipse插件.但是,我在配置转换为Maven项目选项中看不到.我想我已经安装了m2e用于更新的eclipse版本..有没有办法为Eclipse Indigo安装m2e?(在市场上找不到)
求助:最后我卸载并再次安装m2e,现在它工作..我想我第一次安装时做错了.
我正在尝试将最后一个id插入表中.我在用
SELECT IDENT_CURRENT('TABLE')
Run Code Online (Sandbox Code Playgroud)
但问题是它不返回最后插入的id,它返回最大插入id.
例如,如果我这样做:
INSERT INTO 'TABLA' (ID) VALUES (100)
SELECT IDENT_CURRENT('TABLE') returns 100
Run Code Online (Sandbox Code Playgroud)
但是如果我这样做的话
INSERT INTO 'TABLA' (ID) VALUES (50)
SELECT IDENT_CURRENT('TABLE') returns 100
Run Code Online (Sandbox Code Playgroud)
我想要50岁
我需要一个特定的表的ID,并且我在dinamically中生成id,所以它不是一个标识我该怎么做?