Announcement

Collapse
No announcement yet.

How to get text from CMD command output in AMS?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get text from CMD command output in AMS?

    Hello, I have been investigating in the forum but I have not found anything. I need to store in a variable the output of a command in CMD for example:
    getmac or ipconfig / all. I understand that it can be done with the CommandLine plugin but I cannot find information about its use in "Plugin Help"
    Thanks


    This is what I have

    Code:
    data = CommandLine.Execute("getmac", 0);
    Input.SetText("Input1", data)

  • #2
    You need no plugin for this.
    Code:
    local sCommand = "\"".._SystemFolder.."\\getmac.exe\"";
    local tOutput = {};
    for sLine in io.popen(sCommand):lines() do
       -- get the output and put each line into a table
       if (String.Length(String.TrimLeft(String.TrimRight(sLine))) > 0) then
          -- skip empty lines
          Table.Insert(tOutput, #tOutput + 1, String.TrimLeft(String.TrimRight(sLine)));
       end
    end
    
    -- show the output
    local sOutput = "";
    for i = 1, #tOutput do
       sOutput = sOutput .. "line " .. i .. ": " .. tOutput[i] .. "\r\n";
    end
    Dialog.Message("output", sOutput);
    Ulrich

    Comment


    • #3
      Originally posted by Ulrich View Post
      You need no plugin for this.
      Code:
      local sCommand = "\"".._SystemFolder.."\\getmac.exe\"";
      local tOutput = {};
      for sLine in io.popen(sCommand):lines() do
      -- get the output and put each line into a table
      if (String.Length(String.TrimLeft(String.TrimRight(sL ine))) > 0) then
      -- skip empty lines
      Table.Insert(tOutput, #tOutput + 1, String.TrimLeft(String.TrimRight(sLine)));
      end
      end
      
      -- show the output
      local sOutput = "";
      for i = 1, #tOutput do
      sOutput = sOutput .. "line " .. i .. ": " .. tOutput[i] .. "\r\n";
      end
      Dialog.Message("output", sOutput);
      Ulrich
      Hello thanks for the answer, I didn't know that there was an .exe but in case you want to extract it directly from a command? like "wmic path win32_computersystemproduct get uuid" which is not found as .exe in windows but can only be obtained by cmd

      Comment


      • #4
        Try changing the first line of my sample code to
        Code:
        local sCommand = "wmic path win32_computersystemproduct get uuid";
        and then execute the project.

        wmic is also an executable, you find it in _SystemFolder\Wbem\wmic.exe, but as it is in the PATH environment variable, you can suppress the full path when calling it.

        Ulrich

        Comment


        • #5
          Click image for larger version

Name:	error.png
Views:	131
Size:	43.2 KB
ID:	307919

          I am getting error. I'm sorry I'm very new, anyway this helps me a lot to advance in what I was doing

          Comment


          • #6
            Compare your line 5 with my sample code, there is an extra space in your code.

            Ulrich

            Comment


            • #7
              It works, thank you very much have a good day

              Comment

              Working...
              X