I have a c# console application that I invoke with a server call in PHP
chdir($filePath);
exec($filePath.$fileName);
This works great, the application is run. The data it is designed to collect is collected and everyone is happy.
Currently I have plans on storing the one time use information on a server or a flat file, but then I noticed that while the console application is running and doing it's magic the page hangs waiting for the application to stop. This intrigued me, and now i'm wondering if there is a way for the application to pass it's data back to the page directly?
Note: I'm running Apache2 on Windows 7
Update:
Ended up using
$runCommand = "D:\\ScanBoyConsole\\ScanBoy_Console.exe COM1 9600 8 1 0 1";
$WshShell = new COM("WScript.Shell");
$output = $WshShell->Exec($runCommand)->StdOut->ReadAll;
json_decode($output);
If you mean by "directly" that you want the application's output sent to the client while it's still running you might be interested in passthru().
If you're also the author of the C# application you could skip the console application and expose the functionality in a way accessible via php's COM and .Net module.
The console app should be able to print (using Console.WriteLine), and PHP can take the results of that...
Back in my PHP days, we called scripts all the time (that are nothing but console apps basically) and had the results spit out to the page.
"shell_exec — Execute command via shell and return the complete output
as a string"
http://php.net/manual/en/function.shell-exec.php
[So, the only difference is that you should use shell_exec instead of a regular exec]
Related
I wrote an application that use grpc with ASP.NET client/server.
This application is built for watch and inform about some operations.
Because I would to have an application also compatible with linux, I transformed it in a dll, then for Windows I made a little exe that uses it, with an icon in the systray.
It works for Windows, I must test for linux except for a part, I would to get the addresses used by the server after launching... it works if I back the dll in console mode, but with the short "launcher" it's impossible (add by edit) to get the addresses with the code i wrote between balises, BUT you can connect to the server (by example i changed port in config file to verify if it was not an address by default and it works.). My problem is only to retrieve addresses after launch, i need them to add the possibility to receive a mail with addresses to connect, show them in systray..
Yesterday I found this way to get addresses used:
public void Configure(IApplicationBuilder app,...)
{
string ServerAddress = app.ServerFeatures.Get<IServerAddressesFeature().Addresses.FirstOrDefault();
// ---
}
with the short launcher the string is null while it works when I back transform the dll as a program and launch it.
I would to have an easy way, without to make big modifications when I make an app for a system or another, I have chosen what was the more compatible and would to stay in this way if possible. I know i could make an identifier to know on which system I then launch according to the OS, but i hoped to find another way in case I want to make something else with this app.
Edit:
It seems it could be a problem between the fact to launch a systray that launch Kestrel. I'm beginner with Asp .net. I copy/paste contract and constructor to the systray, it seems i have the same problem (i used a different port). I can connect but IApplicationBuilder don't have the list of adresses used.
How can I directly read a value from Windows Service with VB6?
I wrote a Windows Service with C# which generate a string and I want to read this value with VB6.
For example, Windows Service Application generate a string variable like this for each 10 second:
string id = "1422144";
after 10 second
string id = "2462778";
I want to read this values with VB6 each 10 second. I can read it from text file when I create and write this value to text with Windows Service but I don't want to create a text file. Thanks in advance.
To use MSMQ (Message Queue) approach (note, I've not checked this exhaustively so it's just to get started):
https://msdn.microsoft.com/en-us/library/ms973860.aspx
http://www.informit.com/articles/article.aspx?p=131272&seqNum=6
To create self-hosted OWIN Web Api 2.0 service, I'd recommend using TopShelf (I've done this myself, but too much overhead for just passing a simple string along):
https://codeopinion.com/self-host-asp-net-web-api-as-a-windows-service/
Other options:
Communicate via TCP/IP directly
Use a database (server updates, VB6 reads)
use compicated system of arduino-activated relays to cause mice to take particular paths in a maze, and detect their movements (note: not entirely serious)
Lots of things I've not thought of
Okay I succeeded in creating a custom Minecraft launcher for my server. Everything is working fine but there is one cool thing i would like to add. I think it would be cool if people can instantly join a server upon launching minecraft. Does anyone know if this is possible to do?
Have you seen:
http://minecraft.gamepedia.com/Minecraft_launcher
Specifically the section called
Command Line usage
MinecraftDev.jar (all systems): java -cp Minecraft.jar net.minecraft.bootstrap.Bootstrap <username> <server:port>.
Beginning with the launcher released with Minecraft 1.6.1, there are
other commands for the launcher. These can be seen by running java
-jar Minecraft.jar -help.
this shows you it is possible to launch minecraft telling it to connect to server. you should check out the -help to see the full list of command line arguments
I have a system for sending E-mails to users by a specific time .
built in ASP.NET MVC4 and has an action result "function" for checking the time of messages and send it if the day of the message is today .
how can I call this action result (daily) -like a scheduler- in efficient way ?
Thanks.
Whilst a separate service / application would be better, you could use wget.
GNU Wget is a free software package for retrieving files using HTTP,
HTTPS and FTP, the most widely-used Internet protocols. It is a
non-interactive commandline tool, so it may easily be called from
scripts, cron jobs, terminals without X-Windows support, etc.
You would then do something like:
"C:\Program Files (x86)\GnuWin32\bin\wget.exe" --no-check-certificate https://www.exammple.com/YouController/YourAction -O NUL
in a .bat file and set that to run via a windows Scheduled task at the time you require (assuming you don't need to run it less than every 60 seconds - if you do, let me know as I have another way around this using a windows service to call the bat file instead).
Omitting the -O NUL part would also save the output so you could see if everything ran successfully by doing:
public ActionResult YourAction()
{
//Do your code, get some stats that show it ran properly.
return Content("Return your stats here.");
}
from your controller action.
More efficient will be when you create new application as Windows Service. There u can easy set code to start at specific time. in this solution you will have more flexibility and independent. You can start hire : Windows Service to run a function at specified time
You could create a small console application that just calls the API do send out the emails. You can then schedule the console app to run at a specific time using the Windows Scheduler; you can even have it run without showing the console window. See here or here for details on how to schedule a task.
Use Azure Functions, that's exactly what it was built for. It's really good.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-overview
I have a console app that prompts for various pieces of information that I want to invoke from C# via the System.Diagnostics.Process.Start() method from a Windows Form app but I can't quite get it to work correctly. As a simple example lets say I want to capture FirstName, and LastName via a Windows Form application and then pass each to the console app dynamically like this:
Forms app launches, the user keys in the values for firstname and lastname and clicks a button to submit
it calls Process.Start for the console app
Console app writes out 'Enter your first name"
Forms app reads this prompt, identifies that it needs to respond with the FirstName value it has collected and writes it to the console app's output
Console app accepts the input and responds with the next prompt "Enter your last name"
Forms app reads this prompt, identifies that it needs to respond with the LastName value it has collected and writes it to the console app's output
Console app now has all the information it needs and continues on its merry way
thanks for any insight, this is not an area I have worked with much at all
From the WinForms app, you can read output from the console app with the StreamReader returned by the Process.StandardOutput property, and write input to the console app with the StreamWriter returned by the Process.StandardInput property.
BTW, did you develop the console app yourself (or have the project files)? If so, I'd suggest using a better form of IPC, such as making the console app a DLL intead of an EXE, or using something from WCF or something like that.
Look at Process.StandardOutput and Process.StandardInput and Process.StandardError.
You need to read from Process.StandardOutput. When you read " 'Enter your first name"" then you write the first name to Process.StandardInput and so on.
Note that the child process can write to its StandardError as well and you probably need to read from it in a different thread so that you can read concurrently from both
In Java there is expect4j that makes this easy. I am pretty sure I saw something on .net but but I am not able to find it right now.
EDIT: Creating a Child Process with Redirected Input and Output seems to be a good article on this topic on MSDN