请教shell高手:怎样将 date +%C%y%m%d 的执行结果(20020709)赋给一个字符变量? 谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CString strYour;strYour.Format("%s",date +%C%y%m%d ) CString strYour;strYour.Format("%d",date +%C%y%m%d ); 用CreateProcess(),可以用来得到控制台程序的返回字符串,这里是一个和delphi的例子:function ThreadComp.RunTerminal(const Prog, CommandLine,Dir: String;var ExitCode:DWORD): String;var HRead,HWrite:THandle; StartInfo:TStartupInfo; ProceInfo:TProcessInformation; b:Boolean; sa:TSecurityAttributes; inS:THandleStream; sRet:TStrings;begin Result := ''; FillChar(sa,sizeof(sa),0); //ÉèÖÃÔÊÐí¼Ì³Ð£¬·ñÔòÔÚNTºÍ2000ÏÂÎÞ·¨È¡µÃÊä³ö½á¹û sa.nLength := sizeof(sa); sa.bInheritHandle := True; sa.lpSecurityDescriptor := nil; b := CreatePipe(HRead,HWrite,@sa,0); CheckResult(b); FillChar(StartInfo,SizeOf(StartInfo),0); StartInfo.cb := SizeOf(StartInfo); StartInfo.wShowWindow := SW_HIDE; //ʹÓÃÖ¸¶¨µÄ¾ä±ú×÷Ϊ±ê×¼ÊäÈëÊä³öµÄÎļþ¾ä±ú,ʹÓÃÖ¸¶¨µÄÏÔʾ·½Ê½ StartInfo.dwFlags := STARTF_USESTDHANDLES+STARTF_USESHOWWINDOW; StartInfo.hStdError := HWrite; StartInfo.hStdInput := GetStdHandle(STD_INPUT_HANDLE);//HRead; StartInfo.hStdOutput := HWrite; b := CreateProcess(PChar(Prog),//lpApplicationName: PChar PChar(CommandLine), //lpCommandLine: PChar nil, //lpProcessAttributes: PSecurityAttributes nil, //lpThreadAttributes: PSecurityAttributes True, //bInheritHandles: BOOL CREATE_NEW_CONSOLE, nil, PChar(Dir), StartInfo, ProceInfo ); CheckResult(b); WaitForSingleObject(ProceInfo.hProcess,INFINITE); GetExitCodeProcess(ProceInfo.hProcess,ExitCode); inS := THandleStream.Create(HRead); if inS.Size>0 then begin sRet := TStringList.Create; sRet.LoadFromStream(inS); Result := sRet.Text; sRet.Free; end; inS.Free; CloseHandle(HRead); CloseHandle(HWrite);end; CString str=date.Format("%Y%m%d"); 如何在视频画面上用鼠标画矩形框 如何获得windows桌面的dc 64位的程序能在32位程序里用createprocess或shellEx什么什么这些函数调用吗? delete AfxBeginThread返回值 CString(unicode编码的) to char * 安装不了vc 请问开发DirectX 2D程序 用VC.net和VC6.0哪个比较适合? 各位各哥我想动态生成滑动条,这样的代码行不行,请看看... CSpinButtonCtrl 如何锁定单独轮廓 wry.dll的格式,怎么创建临时文件! 请问如何在一个菜单项前打上一个对号?在程序里如何写??谢谢!
strYour.Format("%s",date +%C%y%m%d )
strYour.Format("%d",date +%C%y%m%d );
var
HRead,HWrite:THandle;
StartInfo:TStartupInfo;
ProceInfo:TProcessInformation;
b:Boolean;
sa:TSecurityAttributes;
inS:THandleStream;
sRet:TStrings;
begin
Result := '';
FillChar(sa,sizeof(sa),0);
//ÉèÖÃÔÊÐí¼Ì³Ð£¬·ñÔòÔÚNTºÍ2000ÏÂÎÞ·¨È¡µÃÊä³ö½á¹û
sa.nLength := sizeof(sa);
sa.bInheritHandle := True;
sa.lpSecurityDescriptor := nil;
b := CreatePipe(HRead,HWrite,@sa,0);
CheckResult(b); FillChar(StartInfo,SizeOf(StartInfo),0);
StartInfo.cb := SizeOf(StartInfo);
StartInfo.wShowWindow := SW_HIDE;
//ʹÓÃÖ¸¶¨µÄ¾ä±ú×÷Ϊ±ê×¼ÊäÈëÊä³öµÄÎļþ¾ä±ú,ʹÓÃÖ¸¶¨µÄÏÔʾ·½Ê½
StartInfo.dwFlags := STARTF_USESTDHANDLES+STARTF_USESHOWWINDOW;
StartInfo.hStdError := HWrite;
StartInfo.hStdInput := GetStdHandle(STD_INPUT_HANDLE);//HRead;
StartInfo.hStdOutput := HWrite; b := CreateProcess(PChar(Prog),//lpApplicationName: PChar
PChar(CommandLine), //lpCommandLine: PChar
nil, //lpProcessAttributes: PSecurityAttributes
nil, //lpThreadAttributes: PSecurityAttributes
True, //bInheritHandles: BOOL
CREATE_NEW_CONSOLE,
nil,
PChar(Dir),
StartInfo,
ProceInfo ); CheckResult(b);
WaitForSingleObject(ProceInfo.hProcess,INFINITE);
GetExitCodeProcess(ProceInfo.hProcess,ExitCode); inS := THandleStream.Create(HRead);
if inS.Size>0 then
begin
sRet := TStringList.Create;
sRet.LoadFromStream(inS);
Result := sRet.Text;
sRet.Free;
end;
inS.Free; CloseHandle(HRead);
CloseHandle(HWrite);
end;