4.45 FAQ-656 How to run Origin from command line?
Last Update: 12/20/2017
One approach to program automation is to execute a program and pass arguments at the Command Line. Here we will present two quick examples of how to automate Origin using the command line.
For a more detailed discussion of this topic, see Customizing Origin Startup Behavior with the Command Line.
Running a Script File
LabTalk scripts are saved to text files that have an OGS extension. The script file can be in the folder of your choice as long as the path is specified in the command line. For more information, see Running Script from Files.
Open a text editor, copy the three lines of code below and save this as a file called Startup.OGS to C:\Temp\.
type -b "hello world";
Then, assuming Origin is installed to C:\Program Files\OriginLab\Origin2018, you can use the following command to execute the script from the command line:
"C:\Program Files\OriginLab\Origin2018\Origin95_64.exe" -h -rs run.section("c:\Temp\Startup.OGS", main)
Origin is launched and the script in the
[Main] section of Startup.OGS is run by specifying the
-rs switch. The Origin application is hidden by the
-h switch (though the Script Window will show if opened by internal control).
Adding a Configuration File
Configuration files can include any LabTalk command, but typically contain menu commands and macro definitions. Additional command line options control initialization files and menu levels. While also quite useful, using these files is more complex than the example presented here. For more information, see Working with Files.
Create a text file named COMMAND.CNF and save it to your User Files Folder. The text file contents should be:
string bkPath$ = system.path.program$ + "Samples\Curve Fitting\Linear Regression.OGW";
doc -o %(bkPath$);
string dataPath$=system.path.program$ + "Samples\Curve Fitting\Sensor01.dat";
sec -p 3;
type -b Automation complete.; // Remove this line for complete automation
Using Windows Run, a command prompt beginning with START, or your application's call to a command shell, you can start Origin and pass the above file as an argument. For example, run the following:
<Origin.EXE path and name> -r run.section(command.cnf, Main)
The example loads an Origin analysis template, imports a sample data file and saves the resulting OPJ to <UFF path>Sensor01.opj (note that when no path is passed to run.section, the User Files Folder is assumed). A message box is displayed to the script has run to completion. When you click the OK button, Origin will close.
Keywords:Command Window, LabTalk, Origin Startup