windows forms and cmd issue. ( arguments )

mion shion 241 Reputation points
2022-10-23T16:23:37.79+00:00

good afternoon -

been trying for a while now to get my argements passed to cmd i know it uses only one string arguments so i done a string join

        public void searchartist(string search)  
        {  
            if (search == string.Empty)  
            {  
                XtraMessageBox.Show("Please Provide search term ");  
            }  
            else  
            {  
                System.Diagnostics.Process p = new System.Diagnostics.Process();  
                p.StartInfo.UseShellExecute = false;  
                p.StartInfo.FileName = "cmd.exe";  
                string[] myargs = { "/c spotdl download ", "'", search, "'" };  
                string elfen = string.Join("", myargs);  
                XtraMessageBox.Show(elfen);  
                p.StartInfo.Arguments = string.Join("",elfen);  
                p.StartInfo.RedirectStandardError = true;  
                p.StartInfo.RedirectStandardInput = true;  
                p.StartInfo.RedirectStandardOutput = true;  
                p.StartInfo.CreateNoWindow = true;  
  
                p.Start();  
  
                StreamReader outputWriter = p.StandardOutput;  
                //String errorReader = p.StandardError.ReadToEnd();  
                String line = outputWriter.ReadLine();  
                while (line != null)  
                {  
                    XtraMessageBox.Show(line);  
                }  
                p.WaitForExit();  
            }  
        }  

the string join shows,
253295-string-join-output.png

however this is not working well its just showing in the line

Searching Spotify for song named "download"...

but have no idea why its doing this when the arg passed is one string

any help would be much appreiated
elfenliedtopfan5

Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2022-10-23T19:17:09.993+00:00

    Maybe you should try an intermediate fix of your last loop:

    . . .  
    while (line != null)  
    {  
       XtraMessageBox.Show(line);  
       line = outputWriter.ReadLine(); // ADDED  
    }  
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.