StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Yuichi  
#1 Posted : Wednesday, August 28, 2019 10:20:10 AM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 43
Poland

Thanks: 14 times
Was thanked: 10 time(s) in 9 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")
Rob  
#2 Posted : Wednesday, August 28, 2019 11:46:12 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 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 11:51:03 AM(UTC)  | Reason: clarify use of back ticks, add input string building

Rob  
#3 Posted : Wednesday, August 28, 2019 11:55:19 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 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 11:57:52 AM(UTC)  | Reason: Not specified

Rob  
#4 Posted : Wednesday, August 28, 2019 12:03:02 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 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")
thanks 1 user thanked Rob for this useful post.
Yuichi on 8/28/2019(UTC)
Yuichi  
#5 Posted : Wednesday, August 28, 2019 12:31:51 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 43
Poland

Thanks: 14 times
Was thanked: 10 time(s) in 9 post(s)
So can I get arg "something" using the "Console.ReadLine()" command in Visual Studio?

Originally Posted by: Rob Go to Quoted Post
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")


Rob  
#6 Posted : Wednesday, August 28, 2019 1:15:53 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 401
United States

Thanks: 5 times
Was thanked: 78 time(s) in 68 post(s)
Check these out:

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/command-line-arguments

https://www.geeksforgeeks.org/c-sharp-command-line-arguments/

Basically, your Main function accepts the args then you parse them in your code, so there would be no reading of an input line, it would be passed to the application as an argument.
thanks 1 user thanked Rob for this useful post.
Yuichi on 8/28/2019(UTC)
Yuichi  
#7 Posted : Wednesday, August 28, 2019 2:01:41 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 43
Poland

Thanks: 14 times
Was thanked: 10 time(s) in 9 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
Users browsing this topic
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.