0

I have C++ Windows service which execute batch script via popen function.

FILE *fp;
fp = popen( "C:\\temp\\script.bat", "w" );
fclose(fp);

script.bat just executes echo command which is redirected into file.

echo Hello > c:\temp\output.txt

But after executing this script via service output.txt file is not created (but new process was spawned - I can see it via Process Explorer for example).

Of course it works correctly if I execute this c++ code just as process.

But lets come back to service. What is interesting that if I add @echo off into script.bat then everything works correctly even as a service (I mean output.txt file is created).

@echo off
echo Hello > c:\temp\output.txt

Is it related to some policy that Windows service cannot execute scripts which prints output? Or maybe should I configure something?

piotrp
  • 324
  • 2
  • 6
  • Possible duplicate of [What is the equivalent to Posix popen() in the Win32 API?](http://stackoverflow.com/questions/450865/what-is-the-equivalent-to-posix-popen-in-the-win32-api) – Richard Critten Sep 08 '16 at 12:02
  • Services can't interact with the interactive user in later versions of Windows. –  Sep 08 '16 at 12:03

0 Answers0