v5.0
バッチファイル、外部テキストエディタ、コマンドプロンプトなどの外部プロセスを起動します。
Linux では、Script History にメッセージが記録されない点を除き、Systemコマンドと同じです。また、Windows のSystemコマンドは一時的にコマンドプロンプトをポップアップしますが、このメソッドはポップアップしません。詳細については、CreateProcess
のWin32ドキュメントを参照してください。
oLong = XSIUtils.LaunchProcess( CommandLine, [Blocking], [StartupDirectory] ); |
Long。ブロッキングが true に設定されている場合は子プロセスの終了コードが戻されます。
| パラメータ | タイプ | 詳細 |
|---|---|---|
| CommandLine | String | 実行ファイル名およびコマンドラインオプション。パスやファイル名の途中にスペース文字がある場合は、忘れずにクォーテーションで囲んでください。たとえば、"C:¥My Programs¥myeditor.exe"のようにクォーテーションで囲むことにより、C:¥My.exeと認識されることを防げます。 |
| Blocking | Boolean | ブロッキングを True に設定すると、子プロセスの実行が完了するまでSoftimage が復帰しません。
デフォルト値: false |
| StartupDirectory | String | プロセスの初期ディレクトリ。設定しない場合は Softimage のカレントワーキングディレクトリからプロセスが起動されます。このオプションはコマンドプロンプトを起動するときに便利です。 |
'
' This example launchs a command prompt with the directory set
' to the current user path
'
' The new command prompt inherits all the environmental variables
' from Softimage so it will behave like a Softimage command prompt
startDir = Application.InstallationPath( siUserPath )
bBlocking = false ' We don't want the command prompt to freeze Softimage
if Application.Platform = "Win32" then
XSIUtils.LaunchProcess "cmd /C start cmd /K title Softimage Command Prompt", bBlocking, startDir
else
XSIUtils.LaunchProcess "xterm", bBlocking, startDir
end if
|
/*
This example shows how the XSIUtils.LaunchProcess method can be used to execute an
external process. In this case it shows spdlcheck can be used to test a spdl directly
from within scripting.
*/
if ( Application.Platform == "Win32" )
{
var slash = "\\" ;
}
else
{
var slash = "/" ;
}
// Path to one of the spdl files that ships with Softimage
var twistSpdl = Application.InstallationPath( siFactoryPath ) + slash + "Application"
+ slash + "spdl" + slash + "twistop.spdl" ;
var strResults = SpdlCheckFile( twistSpdl ) ;
if ( strResults == "" )
{
LogMessage( "Spdl is OK" ) ;
}
else
{
LogMessage( "Spdl is busted:\n" + strResults ) ;
}
// Helper function that runs spdlcheck on the provided file path.
// Returns:
// - an empty string if the spdl is ok.
// - the error details output by spdlcheck if there is a problem.
function SpdlCheckFile( in_file )
{
// We will launch "spdlcheck" and tell it to output
// its results into a temporary file
var tmpFile = Application.InstallationPath( siUserPath ) + slash
+ "spdlcheckoutput.tmp" ;
var cmd = "spdlcheck -nologo -noverbose -out \"" + tmpFile + "\" \"" + in_file + "\"";
Logmessage( "This command line will be executed:\n" + cmd ) ;
// Specify true for the blocking argument so that our script waits until spdlcheck
// has finished before trying to read the output file
XSIUtils.LaunchProcess( cmd, true ) ;
var oFSO = new ActiveXObject( "Scripting.FileSystemObject" ) ;
var oTextFile = oFSO.OpenTextFile(tmpFile, 1 ) ;
// We expect a string like:
// "Compilation succeeded c:\Softimage\<....>\Application\spdl\twistop.spdl (XSI Object)"
fileAsStr = oTextFile.ReadAll() ;
oTextFile.Close() ;
oFSO.DeleteFile( tmpFile ) ;
// If we find the string "Compilation succeeded" then we would know that
// we were successful
if ( -1 != fileAsStr.search( /Compilation succeeded/ ) )
{
return "" ;
}
// Return the error details
return fileAsStr ;
}
|