Gatan | AMETEKSkip to Main Content
No options found

Calling a Command-Line command from script and showing its output

DigitalMicrograph Script

The script uses the Command-Line command "ipconfig" and outputs its results into a new text window of DigitalMicrograph. The script is a useful blueprint for similar tasks that can be performed from the regular Windows Command-Line.

Preview

string filePath = "C:\\IPconfigInfoDump.txt"
if ( DoesFileExist( filePath ) )
{
	If ( !OKCancelDialog( "Found file at provided path:\n\n" + filePath +"\n\n Delete it?" ) ) exit(0)
	DeleteFile( filePath )
}

string msg = "cmd.exe /c "	// calling the windows command prompt, /c prevents the console from being shown
msg += "ipconfig "		// a command-prompt command
msg += ">> " + filePath		// piping output to the text file

number exitCode = LaunchExternalProcess( msg, 60 )
if ( 0 != exitCode )
	Throw( "Command did time out after 60 sec." )

if ( DoesFileExist( filePath ) )
{
	NewScriptWindowFromFile( filePath ) // Open Text file
}