0

I'm a working on a winform app which took arguments from cmd (or any other command sending program) at run time. I'm successful in getting args at run time but I've to return the status as a string from where the command was executed without exiting the app.

Lets say, I execute the php script like to give args to my running app like:

<?php
   $output = shell_exec('MyApp args');
   echo "<pre>$output</pre>";
?>

Now, i want to return string value to $output variable. Is there any way to return the value from c# winform app.

Rahul Vashishtha
  • 688
  • 6
  • 22
  • When you run a process, it returns an exit code (int) not a string. Or Maybe I don't get what you are asking.... – Eser Apr 02 '16 at 21:02
  • 1
    I've not come across this particular scenario before, but try `Console.WriteLine("the status");` and see if that does what you need. – Glen Thomas Apr 02 '16 at 21:05
  • The usual way to do this to use [StandardOutput](https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx), but I'm not familiar with how you could interact with this in php. – TVOHM Apr 02 '16 at 21:39
  • @GlenThomas I tried Console.WriteLine("Executed A"); is not working. – Rahul Vashishtha Apr 02 '16 at 21:44
  • Does $output contain anything at all or its just blank? – Glen Thomas Apr 02 '16 at 22:14
  • @Glen Thomas its black – Rahul Vashishtha Apr 02 '16 at 22:19
  • Can you try `start /wait MyApp args` to see if your code is returning before output has happened? – Glen Thomas Apr 02 '16 at 22:19
  • Just go to properties and choose output type = console application. The form still will be opened and you can write messages on console as well. This question is a duplicate of a duplicate and has been asked for years. – derloopkat Apr 02 '16 at 22:53
  • It is not clear at all what you're asking. A console program can only "return" an integer value. But of course it can also write text to stdout. The latter _might_ work, but it depends on how PHP works and you didn't include the [tag:php] on your post, so many of the people reading your question have no idea how PHP would receive output sent to stdout. What part of this question are you asking about? Do you want to know how to write to stdout? Or do you want to know how to get PHP to _read_ from a program's stdout? – Peter Duniho Apr 03 '16 at 02:10
  • @Peter Duniho I want to know how to write to stdout – Rahul Vashishtha Apr 03 '16 at 04:03
  • See marked duplicate. – Peter Duniho Apr 03 '16 at 04:13

0 Answers0