StrokesPlus.net Forum
»
General Discussion
»
Plug-Ins
»
Communication with app using STDIN STDOUT
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
Hi I know this topic is not entirely about Strokes+Net but it's worth asking.
I am creating an application (not as a library / plugin) that will communicate with S+Net using Standard Input / Standard Output / Standard Error because I do not want to use information transfer via txt file.
The problem is as follows: somehow I was able to send information from my application using "Console.WriteLine("")" command in Visual Studio, but I don't know how to send information from S+Net to my application and how to receive it in this application. Is the "start.Arguments" command in S+Net responsible for this?
The stdout and stderr test script that I use:Code:var start = new clr.System.Diagnostics.ProcessStartInfo();
start.Arguments = "/c DIR c:\\";
start.FileName = sp.ExpandEnvironmentVariables("%ComSpec%");
start.UseShellExecute = false;
start.CreateNoWindow = false;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
var proc = clr.System.Diagnostics.Process.Start(start);
proc.WaitForExit();
out = proc.StandardOutput.ReadToEnd();
err = proc.StandardError.ReadToEnd();
sp.MessageBox("STDOUT:\n" + out +
"\n\nSTDERR:\n" + err, "STD test")
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
I don't really have a lot of experience in this area, so there may be more elegant solutions available. But if it's simple communication, you could pipe input to the program like this: Code://First, create a C:\Temp\deleteme folder, put one or more files to delete inside it
var start = new clr.System.Diagnostics.ProcessStartInfo();
//Pipe "n" to the del command to answer No (do not delete files)
start.Arguments = `/c echo n|del c:\\temp\\deleteme`;
//Use this line to pipe "y" to delete the files in the deleteme folder
//start.Arguments = `/c echo y|del c:\\temp\\deleteme`;
start.FileName = sp.ExpandEnvironmentVariables("%ComSpec%");
start.UseShellExecute = false;
start.CreateNoWindow = false;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
var proc = clr.System.Diagnostics.Process.Start(start);
proc.WaitForExit();
out = proc.StandardOutput.ReadToEnd();
err = proc.StandardError.ReadToEnd();
sp.MessageBox("STDOUT:\n" + out +
"\n\nSTDERR:\n" + err, "STD test")
Edit: I only used the back ticks (`) because I was testing another method at first which used quotes. Edit 2: So just build your string in the script like: Code:var inputCmd = "some string";
start.Arguments = "/c echo "+inputCmd+"|c:\\MyApp.exe";
Edited by user Wednesday, August 28, 2019 5:51:03 PM(UTC)
| Reason: clarify use of back ticks, add input string building
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
Otherwise, you could create a timer script right before you start the app, give the timer a little delay and have it sendkeys to send the input directly (haven't tested this out, FYI), assuming the app will be the foreground window upon calling .Start. Edit: Wait, maybe you don't need a timer, just sendkeys before the WaitForExit line Edited by user Wednesday, August 28, 2019 5:57:52 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
Also, if you're writing this app, you can have it parse the arguments, then just pass those in: Code:var start = new clr.System.Diagnostics.ProcessStartInfo();
start.Arguments = "something"; //or: something=whatever
start.FileName = "c:\\MyApp.exe";
start.UseShellExecute = false;
start.CreateNoWindow = false;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
var proc = clr.System.Diagnostics.Process.Start(start);
proc.WaitForExit();
out = proc.StandardOutput.ReadToEnd();
err = proc.StandardError.ReadToEnd();
sp.MessageBox("STDOUT:\n" + out +
"\n\nSTDERR:\n" + err, "STD test")
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
So can I get arg "something" using the "Console.ReadLine()" command in Visual Studio?
Originally Posted by: Rob Also, if you're writing this app, you can have it parse the arguments, then just pass those in: Code:var start = new clr.System.Diagnostics.ProcessStartInfo();
start.Arguments = "something"; //or: something=whatever
start.FileName = "c:\\MyApp.exe";
start.UseShellExecute = false;
start.CreateNoWindow = false;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
var proc = clr.System.Diagnostics.Process.Start(start);
proc.WaitForExit();
out = proc.StandardOutput.ReadToEnd();
err = proc.StandardError.ReadToEnd();
sp.MessageBox("STDOUT:\n" + out +
"\n\nSTDERR:\n" + err, "STD test")
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
What i want to send to this app is one string with pdf dimensions, and the "Environment.GetCommandLineArgs()" command in VS solved the problem.
Thx Rob
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
Plug-Ins
»
Communication with app using STDIN STDOUT
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close