DASH CLI 2.1 supports new options to enable developers to send request query in JSON format to DASH systems and get the output in JSON format. The output can be interpreted by any programming language supporting JSON format. The output JSON is modeled similar to Redfish Schema published by DMTF.
In typical usage, DASH CLI is launched with request JSON. DASH CLI processes the request and forms the response in JSON format. This response is sent back to the launching application.
JSON is supported by almost all modern programming languages. Hence it will be easier to add DASH capability into any application or tool with few simple steps. Since the application will be launching DASH CLI, the integration with the application is therefore ‘loosely coupled’. DASH communication, DASH standards compliance, DASH security & stability are encapsulated within DASH CLI. The calling application doesn’t have to know anything about DASH standard.
There are two new options in DASH CLI:
- jdo option: With this flag, DASH request input is taken from command-line and output DASH response is written to console.
- ji/jo option: With this flag, DASH request input is taken from file and output DASH response is written file.
jdo option is faster since it doesn’t involve any file operation.
Before starting
- Download and install DASH CLI 2.1 version. In this blog, DASH CLI is installed in default path, “C:\Program Files (x86)\DASH CLI 2.1\”
- Examples are illustrated with Visual Studio 2017. But any other IDE or editor can be used.
- Refer DASH CLI Developer Guide, which is available in DASH CLI installation folder: “C:\Program Files (x86)\DASH CLI 2.1\docs\”, for JSON request & response formats for supported DASH profiles.
- This blog provides the steps for C# .NET language. Sample code for using -jdo, -ji & -jo options is attached.
JDO Flag usage
Using via direct command line
dashcli -jdo
When this command is run, DASH CLI waits for input in JSON format. Once the input is provided, it will be executed by DASH CLI and output of which is written back in JSON format, as shown in the screenshot below.
![Input_Masked_JDO]()
Using JDO programmatically
Create a sample C# application by following the steps below:
Step 1: Create a new project in Visual Studio by selecting from the Menu “File” > “New” > “Project”
![]()
Step 2: Select “Visual C#” -> “Console App (.net Framework)”. Name the application “SampleJDO” and click “OK” button.
![]()
Step 3: Add the two constant members dashCliDirectory and dashCliPath in “Program.cs” file.
privatestaticreadonlystringdashCliDirectory =@"C:\Program Files (x86)\DASH CLI 2.1\bin\";
privatestaticreadonlystringdashCliPath = dashCliDirectory +@"dashcli.exe";
Step 4: Add the using statements to include “System.Diagnostics” and “System.IO” as these will be referenced in the upcoming code.
usingSystem.Diagnostics;
usingSystem.IO;
Step 5: Define the functions “JdoExample” and “RunDashCli” as shown below:
staticvoidJdoExample() {
stringmemStdIn, memStdOut = String.Empty, memStdErr = String.Empty;
stringinputJsonFile =@"input_json.txt";
memStdIn = Convert.ToString(File.ReadAllText(inputJsonFile));
Console.WriteLine("Input: ");
Console.WriteLine(memStdIn);
stringarguments =@"-jdo";
intreturnCode = RunDASHCli(arguments, memStdIn,outmemStdOut,outmemStdErr);
Console.WriteLine("Output: ");
Console.Write(memStdOut);
//'memStdout' has the result in JSON format
}
staticintRunDASHCli(stringarguments,stringmemStdIn,outstringmemStdOut,outstringmemStdErr) {
memStdOut = String.Empty;
memStdErr = String.Empty;
intexitCode = 1;
Process process =newProcess();
StreamWriter streamWriter =null;
StreamReader streamOutReader =null;
StreamReader streamErrReader =null;
process.StartInfo.UseShellExecute =false;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.StartInfo.WorkingDirectory = dashCliDirectory;
process.StartInfo.RedirectStandardInput =true;
process.StartInfo.RedirectStandardOutput =true;
process.StartInfo.RedirectStandardError =true;
process.StartInfo.FileName = dashCliPath;
process.StartInfo.Arguments = arguments;
try{
process.Start();
streamOutReader = process.StandardOutput;
streamWriter = process.StandardInput;
streamErrReader = process.StandardError;
streamWriter = process.StandardInput;
streamWriter.WriteLine(memStdIn);
streamWriter.Close();
memStdOut = streamOutReader.ReadToEnd();
memStdErr = streamErrReader.ReadToEnd();
process.WaitForExit();
exitCode = process.ExitCode;
streamOutReader.Close();
streamErrReader.Close();
}catch(Exception) {
exitCode = -1;
}finally{
process.Close();
}
returnexitCode;
}
Step 6: Call “JdoExample” function in the “Main” function and surround the call with messages to indicate start and stop of call like so:
Console.WriteLine("Trying JdoExample ...");
JdoExample();
Console.WriteLine("JdoExample done.");
The entire code at this stage should look like so:
usingSystem;
usingSystem.Diagnostics;
usingSystem.IO;
namespaceSampleJDO {
classProgram{
privatestaticreadonlystringdashCliDirectory =@"C:\Program Files (x86)\DASH CLI 2.1\bin\";
privatestaticreadonlystringdashCliPath = dashCliDirectory +@"dashcli.exe";
staticvoidMain(string[] args) {
Console.WriteLine("Trying JdoExample ...");
JdoExample();
Console.WriteLine("JdoExample done.");
}
staticvoidJdoExample() {
stringmemStdIn, memStdOut = String.Empty, memStdErr = String.Empty;
stringinputJsonFile =@"input_json.txt";
memStdIn = Convert.ToString(File.ReadAllText(inputJsonFile));
Console.WriteLine("Input: ");
Console.WriteLine(memStdIn);
stringarguments =@"-jdo";
intreturnCode = RunDASHCli(arguments, memStdIn,outmemStdOut,outmemStdErr);
Console.WriteLine("Output: ");
Console.Write(memStdOut);
//'memStdout' has the result in JSON format
}
staticintRunDASHCli(stringarguments,stringmemStdIn,outstringmemStdOut,outstringmemStdErr) {
memStdOut = String.Empty;
memStdErr = String.Empty;
intexitCode = 1;
Process process =newProcess();
StreamWriter streamWriter =null;
StreamReader streamOutReader =null;
StreamReader streamErrReader =null;
process.StartInfo.UseShellExecute =false;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.StartInfo.WorkingDirectory = dashCliDirectory;
process.StartInfo.RedirectStandardInput =true;
process.StartInfo.RedirectStandardOutput =true;
process.StartInfo.RedirectStandardError =true;
process.StartInfo.FileName = dashCliPath;
process.StartInfo.Arguments = arguments;
try{
process.Start();
streamOutReader = process.StandardOutput;
streamWriter = process.StandardInput;
streamErrReader = process.StandardError;
streamWriter = process.StandardInput;
streamWriter.WriteLine(memStdIn);
streamWriter.Close();
memStdOut = streamOutReader.ReadToEnd();
memStdErr = streamErrReader.ReadToEnd();
process.WaitForExit();
exitCode = process.ExitCode;
streamOutReader.Close();
streamErrReader.Close();
}catch(Exception) {
exitCode = -1;
}finally{
process.Close();
}
returnexitCode;
}
}
}
Step 7: In step 5, the added function “JdoExample”, has defined the input JSON File as input_json.txt. This declaration assumes that input_json.txt is in the same path as the location of the executable. As the default configuration in Visual studio points to Debug folder, please navigate to the debug folder. Upon building the project, the Output window gives the location of the Debug folder.
![]()
Step 8: Put the following JSON test in input_json.txt file:
{"h":"hp705g4-3","u":"admin","P":"adminPass","Commands":["discover"]}
Step 9: Run the SampleJDO.exe application form the console.
![]()
Ji JO Flag usage
Using via direct command line
dashcli -ji input_json.txt -jo output_json.txt
Here, the file ‘input_json.txt’ has the DASH command in JSON format. DASH CLI executes this command and writes the output in JSON format to file specified by -jo option, which is output_json.txt. Usage is shown in the screenshot below.
![]()
Using JI/JO programmatically
Create a sample C# application by following the steps below:
Step 1: Create a new project in Visual Studio by selecting from the Menu “File” > “New” > “Project”
![]()
Step 2: Select “Visual C#” -> “Console App (.net Framework)”. Name the application “SampleJiJO” and click “OK” button.
![]()
Step 3: Add the two constant members dashCliDirectory and dashCliPath in “Program.cs” file.
privatestaticreadonlystringdashCliDirectory =@"C:\Program Files (x86)\DASH CLI 2.1\bin\";
privatestaticreadonlystringdashCliPath = dashCliDirectory +@"dashcli.exe";
Step 4: Add the using statements to include “System.Diagnostics” and “System.IO” as these will be referenced in the upcoming code.
usingSystem.Diagnostics;
usingSystem.IO;
Step 5: Define the functions “JiJoExample” and “RunDashCli” as shown below:
staticvoidJiJoExample() {
stringAppPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) +"\\";
stringinputJsonFile = AppPath +@"input_json.txt";
stringoutputJsonFile = AppPath +@"output_json.txt";
Console.WriteLine("Input File: "+ inputJsonFile);
Console.WriteLine("Output File: "+ outputJsonFile);
stringarguments = String.Format("-ji {0} -jo {1}", inputJsonFile, outputJsonFile);
intreturnCode = RunDASHCli(arguments);
//'outputJsonFile' has the result in JSON format
}
staticintRunDASHCli(stringarguments,stringmemStdIn,outstringmemStdOut,outstringmemStdErr) {
memStdOut = String.Empty;
memStdErr = String.Empty;
intexitCode = 1;
Process process =newProcess();
StreamWriter streamWriter =null;
StreamReader streamOutReader =null;
StreamReader streamErrReader =null;
process.StartInfo.UseShellExecute =false;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.StartInfo.WorkingDirectory = dashCliDirectory;
process.StartInfo.RedirectStandardInput =true;
process.StartInfo.RedirectStandardOutput =true;
process.StartInfo.RedirectStandardError =true;
process.StartInfo.FileName = dashCliPath;
process.StartInfo.Arguments = arguments;
try{
process.Start();
streamOutReader = process.StandardOutput;
streamWriter = process.StandardInput;
streamErrReader = process.StandardError;
streamWriter = process.StandardInput;
streamWriter.WriteLine(memStdIn);
streamWriter.Close();
memStdOut = streamOutReader.ReadToEnd();
memStdErr = streamErrReader.ReadToEnd();
process.WaitForExit();
exitCode = process.ExitCode;
streamOutReader.Close();
streamErrReader.Close();
}catch(Exception) {
exitCode = -1;
}finally{
process.Close();
}
returnexitCode;
}
Step 6: Call “JiJoExample” function in the “Main” function and surround the call with messages to indicate start and stop of call like so:
Console.WriteLine("Trying JiJoExample ...");
JiJoExample();
Console.WriteLine("JiJoExample done.");
The entire code at this stage should look like so:
usingSystem;
usingSystem.Diagnostics;
usingSystem.IO;
namespaceSampleJiJO {
classProgram{
privatestaticreadonlystringdashCliDirectory =@"C:\Program Files (x86)\DASH CLI 2.1\bin\";
privatestaticreadonlystringdashCliPath = dashCliDirectory +@"dashcli.exe";
staticvoidMain(string[] args) {
Console.WriteLine("Trying JiJoExample ...");
JiJoExample();
Console.WriteLine("JiJoExample done.");
}
staticvoidJiJoExample() {
stringAppPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) +"\\";
stringinputJsonFile = AppPath +@"input_json.txt";
stringoutputJsonFile = AppPath +@"output_json.txt";
Console.WriteLine("Input File: "+ inputJsonFile);
Console.WriteLine("Output File: "+ outputJsonFile);
stringarguments = String.Format("-ji {0} -jo {1}", inputJsonFile, outputJsonFile);
intreturnCode = RunDASHCli(arguments);
//'outputJsonFile' has the result in JSON format
}
staticintRunDASHCli(stringarguments) {
stringOut, Err;
returnRunDASHCli(arguments,string.Empty,outOut,outErr);
}
staticintRunDASHCli(stringarguments,stringmemStdIn,outstringmemStdOut,outstringmemStdErr) {
memStdOut = String.Empty;
memStdErr = String.Empty;
intexitCode = 1;
Process process =newProcess();
StreamWriter streamWriter =null;
StreamReader streamOutReader =null;
StreamReader streamErrReader =null;
process.StartInfo.UseShellExecute =false;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.StartInfo.WorkingDirectory = dashCliDirectory;
process.StartInfo.RedirectStandardInput =true;
process.StartInfo.RedirectStandardOutput =true;
process.StartInfo.RedirectStandardError =true;
process.StartInfo.FileName = dashCliPath;
process.StartInfo.Arguments = arguments;
try{
boolprocessStarted = process.Start();
streamOutReader = process.StandardOutput;
streamWriter = process.StandardInput;
streamErrReader = process.StandardError;
streamWriter = process.StandardInput;
streamWriter.WriteLine(memStdIn);
streamWriter.Close();
memStdOut = streamOutReader.ReadToEnd();
memStdErr = streamErrReader.ReadToEnd();
process.WaitForExit();
exitCode = process.ExitCode;
streamOutReader.Close();
streamErrReader.Close();
}catch(Exception) {
exitCode = -1;
}finally{
process.Close();
}
returnexitCode;
}
}
}
Step 7: In step 5, the added function “JiJoExample”, has defined the input JSON File as input_json.txt and output JSON File as output_json.txt. This declaration assumes that input_json.txt is in the same path as the location of the executable. As the default configuration in Visual studio points to Debug folder, please navigate to the debug folder. Upon building the project, the Output window gives the location of the Debug folder.
![]()
Step 8: Put the following JSON test in input_json.txt file:
{"h":"hp705g4-3","u":"admin","P":"adminPass","Commands":["discover"]}
Step 9: Run the “SampleJiJO.exe” application form the console.
![]()
Step 10: Check the content of the “output_json.txt” file using “type” command on the console
![]()
In this blog, DASH Discovery is illustrated. Similarly, other DASH profiles can be accessed by the application by framing the required JSON request. See the ‘DASH CLI Developer Guide’ for JSON format for other supported DASH profiles.
Attachments:
- SampleJDO solution
- SampleJIJO solution
For any further query, drop a note below or contact via mail dashsupport@amd.com
Reference:
- DASH CLI Developer Guide (Available in DASH CLI installation folder: “C:\Program Files (x86)\DASH CLI 2.1\docs\”)
Useful links: