Invoking python script in plugin method
-
I am using NPPlugins.NET for plugin generation. Right now, I am trying to invoke a python script and pass in the current document into it; however, the script itself does not seem to be executing. Here is the code:
internal static void GetCurrentDocumentText() { IntPtr curScintilla = PluginBase.GetCurrentScintilla(); String s = GetDocumentText(curScintilla); string progToRun = "C:\\test.py"; Process proc = new Process(); proc.StartInfo.FileName = "C:\\Users...\\python.exe"; proc.StartInfo.UseShellExecute = true; proc.StartInfo.RedirectStandardOutput = false; proc.StartInfo.Arguments = string.Concat(progToRun, " ", s) proc.Start(); proc.WaitForExit(); } -
proc.StartInfo.UseShellExecute = false;
-
Just curious, you know that there is a python script plugin available, don’t you?
-
@gurikbal-singh Even when I set useShellExecute to false, the python script is still not being invoked. The txt file that my python script is supposed to generate cannot be found anywhere. Any advice on how to resolve this issue?
-
@Ekopalypse are you referring to PyNPP? If so, it doesn’t have all the capabilities that I would like.
-
@Parth-Kurani said:
are you referring to PyNPP
The Python Script plugin is not PyNPP (which I had not heard of until now). It is a plugin which embeds a full Python 2.7 interpreter inside the Notepad++ environment, and allows you to run a script from within Notepad++ that gives Python direct access to the contents of all the files open in Notepad++, along with access to many aspects of the Notepad++ GUI.
For instructions on how to install the Python Script in Notepad++ v7.6.3 and later, see this Guide by @Meta-Chuh (because, unfortunately, Python Script plugin doesn’t currently install using the Plugins Admin interface).
-
No, i was referring to the one @PeterJones mentioned.
-
@Parth-Kurani said:
@gurikbal-singh Even when I set useShellExecute to false, the python script is still not being invoked. The txt file that my python script is supposed to generate cannot be found anywhere. Any advice on how to resolve this issue?
proc.StartInfo.Arguments = string.Concat(progToRun, " ", s)
try { Process Process = new Process(); string keyValues = currentDirectory() + "\\User_Command_Line_Tools_PATH"; string keyValue = currentDirectory() + "\\GnuWin32\\bin"; string envVar = Process.StartInfo.EnvironmentVariables["path"]; if (envVar != null) { string value = envVar + ";" + keyValue + ";" + keyValues; Process.StartInfo.EnvironmentVariables["path"] = value; } else { Process.StartInfo.EnvironmentVariables.Add("path", keyValue); Process.StartInfo.EnvironmentVariables.Add("path", keyValues); } Process.StartInfo.FileName = windir() + "\\cmd.exe"; Process.StartInfo.Arguments = "/c " + richTextBox1.Text; if (filepath().ToString() == filex().ToString()) { Process.StartInfo.WorkingDirectory = currentDirectory() + "\\GnuWin32\\bin"; } else { Process.StartInfo.WorkingDirectory = path.ToString(); } Process.StartInfo.RedirectStandardError = true; Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.RedirectStandardInput = true; Process.StartInfo.UseShellExecute = false; Process.StartInfo.CreateNoWindow = true; Process.Start(); string lined = Process.StandardOutput.ReadToEnd(); string line = Process.StandardError.ReadToEnd(); if (String.IsNullOrEmpty(lined)) { richTextBox2.AppendText(line + Environment.NewLine); } if (String.IsNullOrEmpty(line)) { richTextBox2.AppendText(lined + Environment.NewLine); } Process.WaitForExit(); if (checkBox2.Checked == true) { Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_SETTEXT, 0, richTextBox2.Text); } } catch (Exception ex) { System.Diagnostics.Debug.Write(ex.Message); }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login