- 浏览: 1801805 次
- 性别:
- 来自: 南京
文章分类
最新评论
-
cht的大摩托:
学习
IBM WebSphere Performance Tool / ISA / jca457.jar / ha456.jar / ga439.jar -
leeking888:
有没有linux 64位的相关librfccm.so等包啊?
web test LoadRunner SAP / java / Java Vuser / web_set_max_html_param_len -
paladin1988:
非常不错,多谢了。。
appServer IBM WebSphere / WAS 7 / 8.5 / was commerce -
hzxlb910:
写了这么多
net TCP/IP / TIME_WAIT / tcpip / iperf / cain -
acwyg:
ed2k://|file|LoadRunner.V8.1.is ...
web test performance tools / linux performance tools / windows performance tools
http://www.cocoachina.com/b/?p=171 http://rosettacode.org/wiki/Execute_a_System_Command
In this task, the goal is to run either the ls (dir on Windows) system command, or the pause system command.
在这个例子中展示用不同语言调用外部命令的方法。觉得这个挺有意思,转来给大家看看,也许某一天你会觉得有用。 这些语言包括 Ada 原文在 http://www.rosettacode.org/wiki/Execute_a_System_Command with Interfaces.C; use Interfaces.C; procedure Execute_System is function Sys (Arg : Char_Array) return Integer; pragma Import(C, Sys, "system"); Ret_Val : Integer; begin Ret_Val := Sys(To_C("ls")); end Execute_System; do shell script "ls" without altering line endings 支持版本 gcc version 4.0.1 平台: BSD #include <stdlib.h> int main() { system("ls"); } 支持版本: Visual C++ version 2005 system("pause"); 支持版本: MCS version 1.2.3.1 using System; class Execute { static void Main() { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents=false; proc.StartInfo.FileName="ls"; proc.Start(); } } def ls := makeCommand("ls") ls("-l") def [results, _, _] := ls.exec(["-l"]) when (results) -> { def [exitCode, out, err] := results print(out) } catch problem { print(`failed to execute ls: $problem`) } 支持版本: gforth version 0.6.2 s" ls" system 支持版本: GHCi version 6.6 import System.Cmd main = system "ls" 带屏幕输出的 "ls" : $ls 将输出保存到数组"result": spawn,"ls",result 异步执行,将输出转到LUN "unit",以便在以后读取: spawn,"ls",unit=unit J语言系统命令界面由标准的"task"脚本提供: load’task’ NB. Execute a command and wait for it to complete shell ‘dir’ NB. Execute a command but don’t wait for it to complete fork ‘notepad’ NB. Execute a command and capture its stdout stdout =: shell ‘dir’ NB. Execute a command, provide it with stdin, NB. and capture its stdout stdin =: ‘blahblahblah’ stdout =: stdin spawn ‘grep blah’ 支持版本: Java version 1.4+ 有两种执行系统命令的方法,简单的方法会挂起JVM import java.io.IOException; import java.io.InputStream; public class MainEntry { public static void main(String[] args) { executeCmd("ls -oa"); } private static void executeCmd(String string) { InputStream pipedOut = null; try { Process aProcess = Runtime.getRuntime().exec(string); aProcess.waitFor(); pipedOut = aProcess.getInputStream(); byte buffer[] = new byte[2048]; int read = pipedOut.read(buffer); // Replace following code with your intends processing tools while(read >= 0) { System.out.write(buffer, 0, read); read = pipedOut.read(buffer); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException ie) { ie.printStackTrace(); } finally { if(pipedOut != null) { try { pipedOut.close(); } catch (IOException e) { } } } } } 正确的方法使用进程提供的线程去读取InputStream。 import java.io.IOException; import java.io.InputStream; public class MainEntry { public static void main(String[] args) { // the command to execute executeCmd("ls -oa"); } private static void executeCmd(String string) { InputStream pipedOut = null; try { Process aProcess = Runtime.getRuntime().exec(string); // These two thread shall stop by themself when the process end Thread pipeThread = new Thread(new StreamGobber(aProcess.getInputStream())); Thread errorThread = new Thread(new StreamGobber(aProcess.getErrorStream())); pipeThread.start(); errorThread.start(); aProcess.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException ie) { ie.printStackTrace(); } } } class StreamGobber implements Runnable { private InputStream Pipe; public StreamGobber(InputStream pipe) { if(pipe == null) { throw new NullPointerException("bad pipe"); } Pipe = pipe; } public void run() { try { byte buffer[] = new byte[2048]; int read = Pipe.read(buffer); while(read >= 0) { System.out.write(buffer, 0, read); read = Pipe.read(buffer); } } catch (IOException e) { e.printStackTrace(); } finally { if(Pipe != null) { try { Pipe.close(); } catch (IOException e) { } } } } } 支持版本: UCB Logo SHELL命令返回列表: print first butfirst shell [ls -a] ; .. dosCommand "pause" 支持版本:苹果公司的GCC version 4.0.1 void runls() { [[NSTask launchedTaskWithLaunchPath:@"/bin/ls" arguments:[NSArray array]] waitUntilExit]; } 如果你希望调用系统命令,先执行shell: void runSystemCommand(NSString *cmd) { [[NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:[NSArray arrayWithObjects:@"-c", cmd, nil]] waitUntilExit]; } 同样可以使用上面的C语言调用方法。 Sys.command "ls" my @results = qx(ls); # runs command and returns its STDOUT my @results = `ls`; # dito, alternative syntax system "ls"; # runs command and returns its exit status print `ls`; #The same, but with back quotes exec "ls"; # replace current process with another 另外可以参阅 http://perldoc.perl.org/perlipc.html#Using-open()-for-IPC http://perldoc.perl.org/IPC/Open3.html 首行执行命令,第二行显示输出: @exec($command,$output); echo nl2br($output); 注意这里的‘@’防止错误消息的显示,‘nl2br’ 将 ‘\n’转换为HTML的‘br’ sysobey(’ls’); 支持版本: Python version 2.5 import os code = os.system(’ls’) # Just execute the command, return a success/fail code output = os.popen(’ls’).read() # If you want to get the output data 或者 支持版本: Python version 2.4 (及以上版本) import subprocess output = subprocess.Popen(’ls’, shell=True, stdout=subprocess.PIPE).stdout print output.read() 后者是比较好的方法。 或者 支持版本: Python version 2.2 (及以上版本) import commands stat, out = commands.getstatusoutput(’ls’) if not stat: print out `ls -la` as listing 或者指定任何字符串 ‘ls -la’ shell as listing string = `ls` puts [exec ls] 同样可以使用系统open命令。 set io [open "|ls" r] 获取结果的方法是 set nextline [gets $io] 或者 set lsoutput [read $io] 如果命令是以RW方式打开,可以用同样的方法发送用户的输入。 needs shell " ls" system 直接调用 ls 如果希望获取标准输出 CAPTUREDOUTPUT=$(ls) 在 C-Shell 中可以这样做 set MYCMDOUTPUT = `ls` echo $MYCMDOUTPUT 在Korn Shell 中是这样: MYCMDOUTPUT=`ls` echo $MYCMDOUTPUT24种语言执行外部命令的方法
AppleScript
C
C++
C#
E
Forth
Haskell
IDL
J
Java
Logo
MAXScript
Objective-C
OCaml
Perl
PHP
Pop11
Python
Raven
Ruby
Tcl
Toka
UNIX Shell Ada
AppleScript
C
C++
C#
E
Forth
Haskell
IDL
J
Java
Logo
MAXScript
Objective-C
OCaml
Perl
PHP
Pop11
Python
Raven
Ruby
Tcl
Toka
UNIX Shell
end
发表评论
-
script Ngrinder_TestRunnerInsertMysqlSingle.groovy
2017-06-21 10:49 750s 阿里巴巴Java开发规范手册.zip http:/ ... -
script javascript / Node.js / nodejs / GraphicsMagick / sails
2016-06-02 16:32 621s Node.js http://baike.baid ... -
script php / php-fpm /
2015-02-03 18:16 719s Loadrunner project 006 ... -
script perl / pcre / Perl Compatible Regular Expressions
2013-01-31 13:05 2102正则表达式库 PCRE 8.32 http://ww ... -
script asp / asp error_list / Active Server Page
2011-12-19 00:53 6470ASP / Active Server Page h ... -
script webshell jspWebShell / pythonWebShell / phpWebShell
2011-06-11 11:01 2298google shell http://www.jiun ... -
script js base
2009-10-25 16:23 1370三种不同位置的JavaScrip t 代码的写法 ... -
js calendar / wannianli
2009-09-21 13:41 2491s 二十四节气表 http://baike.b ... -
js statistic / URL code
2009-09-18 21:22 2491s java net unicode / nati ... -
script openLaszlo / openLaszlo Server
2009-09-04 15:17 1817http://www.iteye.com/news/2 ... -
js tools / framework / firebug
2009-02-23 16:03 1592http://imgur. ... -
js Colletion
2009-02-06 15:21 1682调用外部js获取IP地址的方法一 http:// ... -
script python / TurboGears / Django / Pylons / ZOPE
2008-10-25 10:10 3125获取python的版本号 http://hi.baidu ... -
script php / php bbs/ php blog / php cms / php cmf / vhcs2
2008-10-20 12:29 4365php docs http://www.cyberci ... -
script ActionScript / ColdFusion
2008-09-26 13:34 1537Sothink SWF Decompiler V4.5 汉化 ... -
script Groovy / Grails
2008-09-26 01:49 1966s Groovy Groov ... -
script js jquery / ext / aptana / json / dojo / dwr / yui / ligerui
2008-09-24 09:41 3325json JSON与JAVA数据的转换 http: ... -
script VBScript
2008-09-22 01:13 16768VBScript 教程 http://www.w3c ... -
js Connection
2008-09-12 17:13 2429http://guoqinhua1986-126-com.it ... -
script Ruby / Rails / Arachni
2008-09-04 22:26 1711ruby down http://rubyinstal ...
相关推荐
public static int ExecuteCommand(string sql, params SqlParameter[] values) { SqlCommand cmd = new SqlCommand(sql, Connection); cmd.Parameters.AddRange(values); return cmd.ExecuteNonQuery(); } ...
本文实例讲述了C#执行外部命令的方法。分享给大家供大家参考。具体实现方法如下: /// ///executes a system command from inside csharp ///</summary> ...public static int executeCommand(string cmd, in
public static int ExecuteSql(string SQLString) { using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand(SQLString, connection)) { try {...
private void ExecuteCommand(OleDbCommand cmd) { cmd.Connection=m_Connection; try { m_Connection.Open(); cmd.ExecuteNonQuery(); } finally { m_Connection.Close(); } } public DataSet ...
support xp_cmdshell execute arbtriry command support sp_OACreate create Wscript.shell execute arbtriry commnad support xp_dirtree list system directroy support execute SQL Query contact me :...
11. Go to c:\seleniumrubytest where you have the ruby script and execute the command ruby googlesearch.rb. Also make sure that you have the Selenium RC server running. 12. The selenium script will get...
java-cmd-exec 一个简单的ProcessBuilder包装器 例子 公共类Md5sumCommand扩展了Command { @Override ... Command.Result result = command.execute(); System.out.println(result.code); // exit code
Execute the vcvars32.bat or vsvars32.bat or vsvars64.bat file from the Visual Studio directory to allow building on the command line. e.g. "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7...
-- 菜单Pre-Uninstall>,按钮Add Action>Execute Command>Add>。 Command Line: cmd /c $USER_INSTALL_DIR$\uninstall.bat $USER_INSTALL_DIR$ 将该Execute Command移动到第一个。 选中Options中的3个选项。 放在...
启点CE过NP中文December 24 2018:Cheat Engine 6.8.2 Released: Here's a new version for the hollidays. Mainly minor improvements and some small bugfixes, but also a new 'ultimap like' ...Added a system...
打印喷水器 通过在Windows 10和Server 2016/2019上滥用SeImpersonatePrivilege... Spooler service to get a SYSTEM token and then run a custom command with CreateProcessAsUser() Arguments: -c <CMD> Execute th
SCGCQ00445356 (CSET) - Megacli crashes after invoking any command in SGI system with one 9280-8e and 2 quad port qlogic FC cards. SCGCQ00452383 (CSET) - New version MegaCli did not show iBBU06 over ...
After a transaction commits, its effects will persist even if there are system failures. Consistency and isolation are the most important in describing SQL Server’s locking model. It is up to the ...
final Command cmd = CommandManager.findCommand(message); if (cmd.getExecutor() != null){ cmd.getExecutor().execute(this, CommandManager.getArgs(message)); } } else { this.sendQueue....
b) n/a ?initial releaseDescription This package provides a set of functions to control the VariSpec filter, which may be called from C or C++ programs. It incorporates all aspects of the filter ...
It can be used both as command line tool and user application with Swing interface. * InfoJ can be used to generate information about Java class. The output includes all possible data that can be ...
- USB printer: output file creation failure now causes a disconnect - re-implemented "options" parameter for additional options of connected devices (currently only used to set the speed reported ...