当前位置: 首页>>代码示例>>C++>>正文


C++ FileStream::Get方法代码示例

本文整理汇总了C++中FileStream::Get方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::Get方法的具体用法?C++ FileStream::Get怎么用?C++ FileStream::Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileStream的用法示例。


在下文中一共展示了FileStream::Get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: stdoutStream

bool
Process::Run (/*[in]*/ const PathName &		fileName,
	      /*[in]*/ const char *		lpszArguments,
	      /*[out]*/ IRunProcessCallback *	pCallback,
	      /*[out]*/ int *			pExitCode,
	      /*[in]*/  const char *		lpszWorkingDirectory)
{
  MIKTEX_ASSERT_STRING_OR_NIL (lpszArguments);
  MIKTEX_ASSERT_STRING_OR_NIL (lpszWorkingDirectory);

  ProcessStartInfo startinfo;

  startinfo.FileName = fileName.Get();

  if (lpszArguments != 0)
    {
      startinfo.Arguments = lpszArguments;
    }

  startinfo.StandardInput = 0;
  startinfo.RedirectStandardInput = false;
  startinfo.RedirectStandardOutput = (pCallback != 0);
  startinfo.RedirectStandardError = false;

  if (lpszWorkingDirectory != 0)
    {
      startinfo.WorkingDirectory = lpszWorkingDirectory;
    }

  auto_ptr<Process> pProcess (Process::Start(startinfo));

  if (pCallback != 0)
    {
      SessionImpl::GetSession()->trace_process->WriteLine
	("core",
	 T_("start reading the pipe"));
      const size_t CHUNK_SIZE = 64;
      char buf[ CHUNK_SIZE ];
      bool cancelled = false;
      FileStream stdoutStream (pProcess->get_StandardOutput());
      size_t total = 0;
      while (! cancelled && feof(stdoutStream.Get()) == 0)
	{
	  size_t n = fread(buf, 1, CHUNK_SIZE, stdoutStream.Get());
	  int err = ferror(stdoutStream.Get());
	  if (err != 0 && err != EPIPE)
	    {
	      FATAL_CRT_ERROR ("fread", 0);
	    }
	  // pass output to caller
	  total += n;
	  cancelled = ! pCallback->OnProcessOutput(buf, n);
	}
      SessionImpl::GetSession()->trace_process->WriteFormattedLine
	("core",
	 T_("read %u bytes from the pipe"),
	 static_cast<unsigned>(total));
    }
  
  // wait for the process to finish
  pProcess->WaitForExit ();
  
  // get the exit code & close process
  int exitCode = pProcess->get_ExitCode();
  pProcess->Close ();
  if (pExitCode != 0)
    {
      *pExitCode = exitCode;
      return (true);
    }
  else if (exitCode == 0)
    {
      return (true);
    }
  else
    {
      TraceError (T_("%s returned %d"),
		  Q_(fileName),
		  static_cast<int>(exitCode));
      return (false);
    }
}
开发者ID:bngabonziza,项目名称:miktex,代码行数:82,代码来源:Process.cpp


注:本文中的FileStream::Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。