/MyEntry\main.py Secret
Last active
September 8, 2019 12:26
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
action = "" | |
while True: | |
data = input(action + "\n") | |
if len(data) == 0: | |
break | |
action = str(int(data) * 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@python main.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.IO; | |
namespace STDINOUTDemo | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
var entryProcesses = new List<Process>(); | |
// Search the current directory for sub-directories | |
foreach (var entry in Directory.EnumerateDirectories(".\\", "*", SearchOption.TopDirectoryOnly)) | |
{ | |
Console.WriteLine($"Processing directory {entry}..."); | |
// Start the entry's process | |
var p = new Process() | |
{ | |
StartInfo = new ProcessStartInfo() | |
{ | |
// Set the entry's working directory to its directory | |
WorkingDirectory = entry, | |
// Hide the window | |
CreateNoWindow = true, | |
// Start the entry up via its run.bat file | |
FileName = "cmd.exe", | |
Arguments = $"/c run.bat", | |
// Among other things, enable I/O redirection | |
UseShellExecute = false, | |
// Redirect I/O (open it up for automated write/read) | |
RedirectStandardInput = true, | |
RedirectStandardOutput = true | |
} | |
}; | |
p.Start(); | |
entryProcesses.Add(p); | |
} | |
Console.WriteLine("Waiting for processes to start..."); | |
foreach (var p in entryProcesses) | |
{ | |
// Wait for process to write anything to STDOUT | |
p.StandardOutput.ReadLine(); | |
} | |
Console.WriteLine("Entries loaded."); | |
var rng = new Random(); | |
var gameRunning = true; | |
while (gameRunning) | |
{ | |
foreach (var p in entryProcesses) | |
{ | |
int num = rng.Next(100); | |
Console.WriteLine($"Writing {num} to entry {p.StartInfo.WorkingDirectory}."); | |
// Write to STDIN | |
p.StandardInput.WriteLine(num); | |
// Read from STDOUT | |
Console.WriteLine($"Process printed {p.StandardOutput.ReadLine()} in response."); | |
} | |
gameRunning = rng.Next(5) != 0; | |
} | |
foreach (var p in entryProcesses) | |
{ | |
// Write an empty line, which tells the entry to shut down | |
p.StandardInput.WriteLine(); | |
if (!p.WaitForExit(15 * 1000 /*ms*/)) | |
{ | |
// If the entry doesn't understand the game end message or takes too long, kill its process | |
p.Kill(); | |
} | |
p.Dispose(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment