interpreter.cpp

来自「一个可视化的编译器」· C++ 代码 · 共 80 行

CPP
80
字号
#include "StdAfx.h"
#include "Interpreter.h"
namespace LeastLIDE {
using namespace System;
using namespace System::IO;
using namespace System::Diagnostics;


Interpreter::Interpreter():
	onRuning(false)	
{

}

void Interpreter::SetPath(String ^newPath) {
	this->path = newPath;
}

void Interpreter::SetParams(String ^newParams) {
	this->params = newParams;
}

String ^ Interpreter::GetPath() {
	return this->path;
}

String ^ Interpreter::GetParams() {
	return this->params;
}

bool Interpreter::IsRunning() {
	return this->onRuning;
}

void Interpreter::Run(int flag) {
	onRuning = true;
	Process ^interpreterProc = gcnew Process();
	interpreterProc->StartInfo->FileName = this->path;
	interpreterProc->StartInfo->RedirectStandardError = flag?false:true;
	interpreterProc->StartInfo->RedirectStandardInput = flag?false:true;
	interpreterProc->StartInfo->RedirectStandardOutput = flag?false:true;
	interpreterProc->StartInfo->UseShellExecute = flag?true:false;
	interpreterProc->StartInfo->CreateNoWindow = flag?false:true;
	interpreterProc->StartInfo->Arguments = this->params;
	interpreterProc->Exited += gcnew System::EventHandler(this, &Interpreter::onInterpreterExited);
	interpreterProc->Start();
	if (0 == flag) {
		input = interpreterProc->StandardInput;   
		output = interpreterProc->StandardOutput;  
	}
}

int Interpreter::Peek( ) {
	return output->Peek();
}

String ^ Interpreter::Read() {
	String ^buf = gcnew String("");  

	int peekSize = output->Peek();
	
	array<wchar_t> ^readBuf = gcnew array<wchar_t>(peekSize);
	output->Read(readBuf, 0, peekSize);
	String ^retBuf = gcnew String(readBuf);
 	
	return retBuf;
}

void Interpreter::Write(char data) {
	input->Write(data);
}

System::Void Interpreter::onInterpreterExited(System::Object^  sender, System::EventArgs^  e) {
	onRuning = false;
	input->Close();
	output->Close();
}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?