下面是一些 JSL,用于通过 JMP 11 的 RunProgram 函数操作 FTP。 下面是关于 RunProgram 的更多信息。
// this example is specific to Windows because of FTP and RunProgram issues
// you'll need to supply a proper site to open and replace
// anonymous... with proper credentials.
// for the example, build a "junk" directory in the temp folder
temp = Convert File Path( "$TEMP", windows ) || "junk"; // no trail back slash
Create Directory( temp ); // typically: "C:\Users\yourname\AppData\Local\Temp\junk"
// use JMP 11 RunProgram to run ftp; supply a ReadFunction to send all
// results to the JMP log
x = RunProgram(
Executable( "ftp" ),
Options( "-v -n" ),
ReadFunction( Function( {this}, Write( this << read ) ) )
);
x << Write( "open ftp.example.com\!n" ); // site to open
x << Write( "user anonymous YOU@yourcompany.com\!n" ); // credentials
x << Write( "dir\!n" ); // look in the log for the file listing
x << Write( "lcd " || temp || "\!n" ); // local change directory...no trail back slash!
x << Write( "get README\!n" ); // fetch file 1
x << Write( "get index.html\!n" ); // and file 2
x << Write( "disconnect\!n" ); // or just bye if nothing else to do
x << Write( "bye\!n" ); // run program terminates when ftp terminates
// when ftp signals end-of-file for reading, RunProgram must
// really be finished. Wait for it...
While( !(x << isReadEof), Wait( .01 ) );
// display the two files in the temp directory
Write( Load Text File( temp || "\!\README" ) );
Write( "\!n\!n\!n" );
Write( Load Text File( temp || "\!\index.html" ) );
Delete Directory( temp ); // clean up
谢谢jara95在这个帖子对于 FTP 选项。 没有它们,FTP 根本无法运行。
RunProgram 是一个 JSL 函数,用于控制计算机上的命令行界面程序。 FTP 使用命令行界面,而 MS-Paint 不使用。 命令行程序有两个可选的数据流:命令输入流和结果输出流。 RunProgram 让 JMP 将命令写入外部程序的输入流 (stdin) 并从外部程序的输出流 (stdout) 读取输出。
RunProgram 在 Help->Scripting Index 中有描述和一些例子。
外部程序从 JMP 异步运行。 以上,变量X是个处理到外部程序;不要覆盖X直到你完成它,并确保将 RunProgram 返回值存储在一个变量中,比如X所以 RunProgram 不会立即丢失。
除非你使用简单的 RunProgram 接口。 简单接口同步运行,这意味着 RunProgram 在外部程序完成之前不会返回到 JMP。 返回值是外部程序的所有输出。 这是一个应该在您的 Windows 计算机上运行的示例(请耐心等待,对您的计算机执行 5 次 ping 操作需要 5 秒):
RP = RunProgram(
Executable("PING.EXE"),
Options( {"-n 5", "localhost"} ),ReadFunction("text"));
show(RP);
输出看起来像这样
使用 32 字节的数据 Ping [::1]:
来自::1的回复:时间<1ms
来自::1的回复:时间<1ms
来自::1的回复:时间<1ms
来自::1的回复:时间<1ms
来自::1的回复:时间<1ms
::1 的 Ping 统计信息:
数据包:发送 = 5,接收 = 5,丢失 = 0(0% 丢失),
以毫秒为单位的近似往返时间:
最小值 = 0ms,最大值 = 0ms,平均值 = 0ms
ReadFunction("text") 启用此行为;它对于在没有大量监督的情况下运行到完成的程序很有用。
FTP代码可能想要很多监督。 在决定下一个命令应该是什么之前,您可能想要检查命令的输出。 如果必须的话,您可以使用 RunProgram 来执行此操作,但这将很复杂且难以解释,并且下一个人也难以维护。 有一个 WriteFunction,与 ReadFunction 非常相似。 您必须为读取和写入编写 JSL 函数并使它们协调。 当 stdout 上有可用数据或 stdin 可以接受更多数据时,RunProgram 将调用它们。 脚本索引中的一个示例有一个命令列表,它通过 WriteFunction 一次一个地发送到 CMD.EXE。 但它并没有真正研究 ReadFunction 中的标准输出数据……只是打印它。
编辑 2017 年 9 月 30 日:修复格式
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />(通过邮件解决...) 我没有指出需要打开 JSL 日志窗口才能查看结果(如果出现问题则进行调试)。日志窗口默认关闭。查看->日志 (windows) 或窗口->日志 (mac)。
特别是,输出不会出现在 CMD 窗口(黑色 dos-box 窗口)中。除非你运行的程序是cmd.exe。
谢谢!
这看起来不错,但是我在让 ftp 或您的 ping 示例通过 JMP 运行时遇到了一些问题。
通过 runprogram 打开 internet explorer 之类的程序工作正常,但 ping、ftp 甚至指向“C:\Windows\System32\ftp.exe”显示根本没有任何操作发生。
任何想法都将不胜感激,因为这看起来比 jan95 的示例更具可扩展性
非常感谢您发布此信息。这正是我需要知道的。我可以看到 RunProgram 的很多用途。