cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Standard Output Stream of CLI

JosefK
5-Regular Member

Standard Output Stream of CLI

I am trying to add some kind of Interface class to an existing VB Project in order to be able to acces the IMS services.

My current solution uses the command line interface, which works pretty fine. The only problems I have are related to "im createcontent" and "im createissue". In those cases I want to know the ID of the created objects but the streamreader object in my software seems so be empty (please see code snippet) 

VB.NET Code of CmdLineInterface Function: 

    Private Function RunCommandCom(command As String, arguments As String) As String()

        Dim p As Process = New Process()
        Dim pi As ProcessStartInfo = New ProcessStartInfo()
        Dim output As String

        pi.Arguments = " " + "/c" + " " + command + " " + arguments
        pi.FileName = "cmd.exe"
        pi.RedirectStandardOutput = True
        pi.CreateNoWindow = True
        pi.WindowStyle = ProcessWindowStyle.Hidden
        pi.UseShellExecute = False
        p.StartInfo = pi
        p.Start()

        Using streamReader As System.IO.StreamReader = p.StandardOutput
            output = streamReader.ReadToEnd()
            p.WaitForExit()
        End Using

        If output Is "" Then
            Return Nothing
        Else
            Return output.Replace(Chr(13), "").Split(Chr(10))
        End If


    End Function

 

The RunCommandCom() function works fine for querys. Also calling other executables like "ipconfig" works fine. What is the difference when calling "im createcontent"? Is it possible to read back the ID of the created object with this solution? 

3 REPLIES 3
JosefK
5-Regular Member
(To:JosefK)

Ok, I found the problem. Some funny developer decided to send the output of "im createcontent" and "im createissue" to the stderr stream instead of sending it to stdout.

 

Is this a feature or a bug?

MichaelChatel
20-Turquoise
(To:JosefK)

Probably by design - though, it seems confusing design.  Is it status info that is being returned?  I think the CLI directs all the "status" return info, to stderr.  That may be what you're seeing.

 

Some of this, is why customers were pointed to the API over the years, where possible.

JosefK
5-Regular Member
(To:MichaelChatel)

I don't think this is just a status info as I create some issue/content and the returned text contains the ID of this issue/content. So for my understanding this should be sent to stdout. But it's ok as long as I know that i have to search for this infroamtion in the stderr sometimes 🙂

 

And yes, after finishing my work I also thought about using the API next time. But for a quick script, the CLI is perfect...

Top Tags