Skip to content

Commit

Permalink
fix in command line handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lowleveldesign committed Jan 3, 2017
1 parent 2ad7002 commit 99131c8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions send2procmon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

Expand All @@ -15,7 +16,7 @@ static class Program
public static void Main(string[] args)
{
if (ShouldIPrintHelpAndExit(args)) {
PrintHelp();
PrintHelp();
return;
}

Expand All @@ -34,8 +35,7 @@ public static void Main(string[] args)
foreach (var message in messages) {
SplitMessagesIfNecessaryAndSendThemToProcmon(hProcmonDevice, message);
}
}
finally {
} finally {
hProcmonDevice.Dispose();
}
}
Expand Down Expand Up @@ -63,7 +63,7 @@ private static string[] ParseMessages(string[] args)
{
string[] messages = args;
if (args.Length == 0) {
if (Console.In.Peek() == -1) {
if (!IsPipedInput()) {
return new string[0];
}
var l = new List<string>();
Expand All @@ -76,6 +76,16 @@ private static string[] ParseMessages(string[] args)
return messages;
}

private static bool IsPipedInput()
{
try {
bool isKey = Console.KeyAvailable;
return false;
} catch {
return true;
}
}

private static void SplitMessagesIfNecessaryAndSendThemToProcmon(SafeFileHandle hProcmonDevice, string message)
{
if (message.Length <= MaxSingleMessageLength) {
Expand All @@ -97,7 +107,7 @@ private static void SendOneMessageToProcmon(SafeFileHandle hProcmonDevice, strin
{
Debug.Assert(message.Length <= MaxSingleMessageLength);
uint bytesReturned = 0;
if (!NativeMethods.DeviceIoControl(hProcmonDevice, IoCtlCode, message, (uint)(message.Length*2), null, 0u,
if (!NativeMethods.DeviceIoControl(hProcmonDevice, IoCtlCode, message, (uint)(message.Length * 2), null, 0u,
ref bytesReturned, IntPtr.Zero)) {
int err = Marshal.GetLastWin32Error();
if (err == 0x57) {
Expand Down

0 comments on commit 99131c8

Please sign in to comment.