Seventy
Seventy
CC#
Created by Seventy on 5/12/2023 in #help
❔ Getting $StandardIn has not been redirected.$ Error...
public class CmdExecutor
{
private Process process;

public CmdExecutor()
{
InitializeProcess();
}

private void InitializeProcess()
{
process = new Process();

ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false,
CreateNoWindow = true
};

process.StartInfo = startInfo;


process.OutputDataReceived += Process_OutputDataReceived;

process.Start();
process.BeginOutputReadLine();
}

public string ExecuteCommand(string command)
{
try
{
process.StandardInput.WriteLine(command);
process.StandardInput.Flush();
return "";
}
catch (Exception ex)
{
Console.WriteLine("Error executing command: " + ex.Message);
return "";
}
}

private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
}

public void CloseProcess()
{
if(process != null)
{

process.Close();
process.Dispose();
}
}
}
public class CmdExecutor
{
private Process process;

public CmdExecutor()
{
InitializeProcess();
}

private void InitializeProcess()
{
process = new Process();

ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false,
CreateNoWindow = true
};

process.StartInfo = startInfo;


process.OutputDataReceived += Process_OutputDataReceived;

process.Start();
process.BeginOutputReadLine();
}

public string ExecuteCommand(string command)
{
try
{
process.StandardInput.WriteLine(command);
process.StandardInput.Flush();
return "";
}
catch (Exception ex)
{
Console.WriteLine("Error executing command: " + ex.Message);
return "";
}
}

private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
}

public void CloseProcess()
{
if(process != null)
{

process.Close();
process.Dispose();
}
}
}
When i run the execute command method i get StandardIn has not been redirected. as an error. Does anyone know what's up with that?
13 replies
CC#
Created by Seventy on 12/28/2022 in #help
❔ How Is This Done?
3 replies
CC#
Created by Seventy on 12/14/2022 in #help
❔ System.typeloadexception could not find method due to type load error
Code I am using:
async void GamerMethod()
{
//Doing gamer things...


await GamerSpace.Grabber.Should_Send_Hello_World_Message();
}




public static async Task Should_Send_Hello_World_Message()
{
var message = new DiscordMessage("Hello World!");
var client = new DiscordWebhookClient("//my super cool url");
await client.SendToDiscord(message);
Assert.IsTrue(true);
}
async void GamerMethod()
{
//Doing gamer things...


await GamerSpace.Grabber.Should_Send_Hello_World_Message();
}




public static async Task Should_Send_Hello_World_Message()
{
var message = new DiscordMessage("Hello World!");
var client = new DiscordWebhookClient("//my super cool url");
await client.SendToDiscord(message);
Assert.IsTrue(true);
}
Any ideas why i am getting that error? (feel like i am doing something wrong and its really dumb 💀 )
26 replies
CC#
Created by Seventy on 10/26/2022 in #help
Get list of all Classes using Interface.
Is there a way i can get a list of all the classes using this interface?
public interface IConsoleCommand
{
string CommandWord { get;
}
bool Process (string[] args);
}
public interface IConsoleCommand
{
string CommandWord { get;
}
bool Process (string[] args);
}
Here is a class using it:
public class ExampleCommand : IConsoleCommand
{
public string CommandWord { get; } = "example";

public bool Process(string[] args)
{
//Run fancy code here!
//Make sure if the execution of your command was successfull => return true;
//else => return false;
//kind of like this:
if(args.Length == 0 || args == null)
{
MaumConsole.instance.Error("Missing Argument(s)", CommandWord);
return false; // This is optional. Just checking if user entered arguments!
}

if (args[0].Equals("pls", StringComparison.OrdinalIgnoreCase))
{
// yay the entered command was "[prefix][CommandWord] pls" and now i will help by sending some cool data > Debug.log();
MaumConsole.instance.Log("Yay you ran the example command!",CommandWord);
return true;
}
else
{
//oh no
MaumConsole.instance.Error("Wrong Argument(s)",CommandWord);
return false;
}
}
}
public class ExampleCommand : IConsoleCommand
{
public string CommandWord { get; } = "example";

public bool Process(string[] args)
{
//Run fancy code here!
//Make sure if the execution of your command was successfull => return true;
//else => return false;
//kind of like this:
if(args.Length == 0 || args == null)
{
MaumConsole.instance.Error("Missing Argument(s)", CommandWord);
return false; // This is optional. Just checking if user entered arguments!
}

if (args[0].Equals("pls", StringComparison.OrdinalIgnoreCase))
{
// yay the entered command was "[prefix][CommandWord] pls" and now i will help by sending some cool data > Debug.log();
MaumConsole.instance.Log("Yay you ran the example command!",CommandWord);
return true;
}
else
{
//oh no
MaumConsole.instance.Error("Wrong Argument(s)",CommandWord);
return false;
}
}
}
Also is there a way i can create a instance of every class using IConsoleCommand?
10 replies
CC#
Created by Seventy on 8/13/2022 in #help
Extracting string from string?
I have a string that looks kinda like this:
string superCoolString = ""something.something.thisthing","something.something.thisthing","something.something.thisthing" etc..."
string superCoolString = ""something.something.thisthing","something.something.thisthing","something.something.thisthing" etc..."
And i need to get only the "thisthing" part how would i do that?
7 replies