-1

How I can redirect powershell output to my c++ program? Now I am adding | Out-File "MyFileName" to command, then read this file in program. How I can do that without file? I know I can do this by using C# or CLI, but I need something like pipe, that’s perfectly worked with cmd.

  • 2
    Could you be a bit more specific? What do you exactly mean with 'powershell output'. What are you _exactly_ trying to achieve? And what have you _exactly_ tried so far? – dingalapadum Apr 16 '15 at 11:13
  • @dingalapadum I'm try to run powershell command from my program, and save everything that powershell outputs in console, in memory, without saving output in file. – Nick EatMore Apr 16 '15 at 11:42
  • @NickEatMore if you are trying to run powershell from within your executable, then this is certainly not redirection. Redirection is, when you pipe the output of powershell to your executable. – Selçuk Cihan Apr 16 '15 at 11:58
  • @SelcukCihan yes, i am use my program to execute powershell with some params, and then collect all powershell output. In this moment, i am using file, but i wanna do without it. – Nick EatMore Apr 16 '15 at 12:09
  • Googling for c++ powershell yielded http://stackoverflow.com/questions/19634220/c-and-powershell check if suits you – Selçuk Cihan Apr 16 '15 at 12:23
  • @SelcukCihan alredy try it. Cli didn't suits, because it requires .Net – Nick EatMore Apr 16 '15 at 12:40

1 Answers1

0

Pipe perfectly works with native programs, as a proof check this out:

ps | less

which is AFAIK the same as

ps | out-string | less

Less is is a C++ Linux tool. You can get less from chocolatey: cinst less.

majkinetor
  • 8,730
  • 9
  • 54
  • 72