我是新人,说话之前先多谢大家看我的问题
比如吧,ForTest.exe就是这么一个简单的函数,向Log.txt中写了一句话
#include <fstream>using namespace std;
int main(){
ofstream ofs("Log.txt", ios::out|ios::binary);
ofs<<"hello CSDN!"<<endl;
return 1;
}点击button1的代码
#include <windows.h>
#include <shellapi.h>
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
WinExec("ForTest\\ForTest.exe", SW_HIDE);
ShellExecute(0,L"open",L"ForTest\\ForTest.exe",L"",L"", SW_SHOW ); string strCmdLine="ForTest\\ForTest.exe";
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.lpReserved = NULL;
siStartInfo.lpReserved2 = NULL;
siStartInfo.cbReserved2 = 0;
siStartInfo.lpDesktop = NULL;
siStartInfo.dwFlags = 0;
CreateProcess(
NULL,
LPWSTR(strCmdLine.c_str()),
NULL, // process security attributes
NULL, // primary thread security attributes
0, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
// Wait for the processs to finish
DWORD rc = WaitForSingleObject(
piProcInfo.hProcess, // process handle
INFINITE); }WinExec那个运行没效果
ShellExecute Link的时候出错误
CreateProcess的方法是参照一个帖子贴的,运行了也没效果这个问题很简单但是我被困住了,大家帮看看
比如吧,ForTest.exe就是这么一个简单的函数,向Log.txt中写了一句话
#include <fstream>using namespace std;
int main(){
ofstream ofs("Log.txt", ios::out|ios::binary);
ofs<<"hello CSDN!"<<endl;
return 1;
}点击button1的代码
#include <windows.h>
#include <shellapi.h>
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
WinExec("ForTest\\ForTest.exe", SW_HIDE);
ShellExecute(0,L"open",L"ForTest\\ForTest.exe",L"",L"", SW_SHOW ); string strCmdLine="ForTest\\ForTest.exe";
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.lpReserved = NULL;
siStartInfo.lpReserved2 = NULL;
siStartInfo.cbReserved2 = 0;
siStartInfo.lpDesktop = NULL;
siStartInfo.dwFlags = 0;
CreateProcess(
NULL,
LPWSTR(strCmdLine.c_str()),
NULL, // process security attributes
NULL, // primary thread security attributes
0, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
// Wait for the processs to finish
DWORD rc = WaitForSingleObject(
piProcInfo.hProcess, // process handle
INFINITE); }WinExec那个运行没效果
ShellExecute Link的时候出错误
CreateProcess的方法是参照一个帖子贴的,运行了也没效果这个问题很简单但是我被困住了,大家帮看看
就没问题,顺利的就打开了调用命令行的,执行就没结果:(
int main() {
ofstream ofs("Log.txt", ios::out ¦ios::binary);
ofs < <"hello CSDN!" < <endl;
cout<<"ok"<<endl;
system("pause");
return 1;
} 就可以看到,点button以后,输出了ok,但就是写到文件那句就是没有效果
static void Log(string msg)
{
const string filename = "log.txt";
lock (filename)
{
System.IO.File.AppendAllText(filename, msg);
}
}