Oracle中若何间接运转OS敕令(下)
??泉源:網海拾貝?
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlglm(msg_buffer, &buffer_size, &msg_length);
printf("Daemon error while connecting:n");
printf("%.*sn", msg_length, msg_buffer);
printf("Daemon quitting.n");
exit(1);
}?
void?
sql_error()?
{?
char msg_buffer[512];
int msg_length;
int buffer_size = 512;
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlglm(msg_buffer, &buffer_size, &msg_length);
printf("Daemon error while executing:n");
printf("%.*sn", msg_length, msg_buffer);
printf("Daemon continuing.n");
}?
main()?
{?
EXEC SQL WHENEVER SQLERROR DO connect_error();
EXEC SQL CONNECT :uid;
printf("Daemon connected.n");
EXEC SQL WHENEVER SQLERROR DO sql_error();
printf("Daemon waiting...n");
while (1) {?
EXEC SQL EXECUTE?
BEGIN?
/*接收deamon發來的字符*/?
:status := DBMS_PIPE.RECEIVE_MESSAGE('daemon');
IF :status = 0 THEN?
/*取出字符*/?
DBMS_PIPE.UNPACK_MESSAGE(:command);
END IF;
END;
END-EXEC;
IF (status == 0)?
{?
command.arr[command.len] = '';
/*要是是stop,該進程就加入*/?
IF (!strcmp((char *) command.arr, "STOP"))?
{?
printf("Daemon exiting.n");
break;
}?
ELSE IF (!strcmp((char *) command.arr, "SYSTEM"))?
{?
EXEC SQL EXECUTE?
BEGIN?
DBMS_PIPE.UNPACK_MESSAGE(:return_name);
DBMS_PIPE.UNPACK_MESSAGE(:value);
END;
END-EXEC;
value.arr[value.len] = '';
printf("Will execute system command '%s'n", value.arr);
/*運轉os敕令*/?
status = system(value.arr);
EXEC SQL EXECUTE?
BEGIN?
DBMS_PIPE.PACK_MESSAGE('done');
DBMS_PIPE.PACK_MESSAGE(:status);
:status := DBMS_PIPE.SEND_MESSAGE(:return_name);
END;
END-EXEC;
[page]
IF (status)?
{?
printf?
("Daemon error while responding to system command.");
printf(" status: %dn", status);
}?
}?
ELSE?
{?
printf?
("Daemon error: invalid command '%s' received.n",? command.arr);
}?
}?
ELSE?
{?
printf("Daemon error while waiting for signal.");
printf(" status = %dn", status);
}?
}?
EXEC SQL COMMIT WORK RELEASE;
exit(0);
}?
以上代碼起名為daemon.pc,用proc預編譯:?
proc iname=daemon.pc userid=用戶名/暗碼@供職名 sqlcheck=semantics?
失蹤失蹤daemon.c,在用c終止編譯,留意在NT上要把orasql8.lib加上,否則編譯經過進程,銜接沒法經過進程。?
3、在供職器上運轉daemon.exe?
4、在sqlplus運轉測試語句:?
SQL> variable rv number?
SQL> execute :rv := DAEMON.EXECUTE_SYSTEM('ls -la');
PL/SQL 進程已告成完成。?
SQL> execute :rv := DAEMON.EXECUTE_SYSTEM('dir');
PL/SQL 進程已告成完成。?
SQL>?
DBMS_PIPE的用法見oracle的文檔。
版權聲明: 原創作品,答應轉載,轉載時請務必以超鏈接體式格局標明文章 原始情由 、作者信息和本聲明。否則將清查功令責任。
轉載于:https://www.cnblogs.com/zgqjymx/archive/2011/03/07/1975888.html
總結
以上是生活随笔為你收集整理的Oracle中若何间接运转OS敕令(下)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 红旗桌面版本最新应用方式和成绩解答100
- 下一篇: Apache中抑制IP段,在httpd.