0

I found some command line arguments to run generate the CSSLint report in xml format. It is working fine while running through command prompt.

Arguments:

csslint --format=csslint-xml "{SourceDir}\bootstrap.css" > "C:\temp\csslint.xml"

I want to execute it through C# application. I tried the below code.

Process process = new Process()
{
    StartInfo =
    {
        FileName = "cmd.exe",
        Arguments = "csslint --format=csslint-xml " + @"""{SourceDir}\bootstrap.css""" + @" > ""C:\Temp\CssLint.xml""",
        UseShellExecute = false,
        RedirectStandardOutput = true,
        CreateNoWindow = true,
    }
};

process.Start();
process.WaitForExit();

But it is not working. Can i have a solution or idea for this issue?

Also is there any way to generate the CSSLint report for the specified directory? I want to give the directory path instead of file name.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Kathir Subramaniam
  • 1,195
  • 1
  • 13
  • 27

1 Answers1

2

You need to add /Kor /C to cmd to execute a process passed as a parameter, thus:

Arguments = "/C csslint --format=csslint-xml " + @"""{SourceDir}\bootstrap.css""" + @" > ""C:\Temp\CssLint.xml""",

From the documentation:

Options

/C Run Command and then terminate

/K Run Command and then return to the CMD prompt. This is useful for testing, to examine variables

One caveat... the piping (the > "C:\temp\csslint.xml" part of your command line) is not an argument, it's a redirection.

If you are redirecting your stdout (the RedirectStandardOutput = true) from your app, you can capture it directly from C#, no need to pipe it to a file like you are trying to do: you'd need to handle the Process.OutputDataReceived event between your Start and WaitForExit calls, or read from the Process.StandardOutput stream).

As for your second question, the csslint CLI allows passing in a directory instead of a file

Jcl
  • 27,696
  • 5
  • 61
  • 92
  • I tried the arguments as given in this snap https://drive.google.com/open?id=0B2pWtJvbMi5AZEFoaXhxZGxoaXc Your answer is not working for my requirement. I am not sure whether we can give cmd.exe as filename. Did you checked your answer at your end?. Also csslint is not an executable. It just an argument. – Kathir Subramaniam Jul 11 '16 at 09:43
  • Not with your specific setup, of course, but I've ran `cmd.exe` from C# many times – Jcl Jul 11 '16 at 09:44
  • I too ran it many times. but the above given argument alone not working. – Kathir Subramaniam Jul 11 '16 at 09:49
  • I have absolutely no way of having your setup to see what's going on, you'll need to experiment yourself. For a start, take the piping to a file out of the arguments: those won't work as I explained in my answer (those are not "arguments" to your process, that makes the shell redirect your stdout). Then check whether you are receiving any data in the process' stdout (either with the event or with the `StandardOutput` property) – Jcl Jul 11 '16 at 09:52