Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So in my project, I have buttons for selecting an action that a python project will do. When I do the command "py project.py -l query" it only shows the help menu what appears when I do "py project.py". I checked and found out I need to change my code "psi = New ProcessStartInfo(Setting_Data.Text.Split(" ")(0), Setting_Data.Text.Split(" ")(1))" to split the text into more parts but If I add more splits I get the error "Overload resolution failed because no accessible 'New accepts this number of arguments." Does anyone know how to fix this?

What I have tried:

psi = New ProcessStartInfo(Setting_Data.Text.Split(" ")(0), Setting_Data.Text.Split(" ")(1), Setting_Data.Text.Split(" ")(2))
Posted
Updated 28-Apr-20 21:22pm

Quote:
for an example of what I'm trying to do, is I select one of the commands, for example, "py project -l query" and it runs it through Cmd.exe. When I click the run command button it only runs the first two parts of the command "py project.py" what only loads the python script and doesn't do any of the commands but I need it to run the full command.

When you set us a new StartInfo, it only takes a max of two strings: the first is the filename of the application to run, and the second is all the parameters it needs to work on as a single item.

Split doesn't do that: it break the string on every occurence oif teh splitting character.
So your input string:
py project -l query
Gets split into four separate strings:
texy
py 
project 
-l 
query
Instead of using split, get the index of the first space, and use Substring:
VB
Dim cmd As String = "py project -l query"
Dim firstSpace As Integer = cmd.IndexOf(" ")
Dim exe As String = cmd.Substring(0, firstSpace)
Dim param As String = cmd.Substring(firstSpace + 1)
And then pass those to your start info:
VB
psi = New ProcessStartInfo(exe, param)
 
Share this answer
 
Comments
SausageFingers 29-Apr-20 3:41am    
Worked Perfectly.👍
ProcessStartInfo Constructor (System.Diagnostics) | Microsoft Docs[^]

There is no constructor of the ProcessStartInfo class accepting more than two strings as parameters.
You need to separate your input into two fields: executable name and command line arguments; thus, splitting it on whitespaces may not be the best way to go. Having an example of the input string would help suggesting a way.
 
Share this answer
 
@phil.o, for an example of what I'm trying to do, is I select one of the commands, for example, "py project -l query" and it runs it through Cmd.exe. When I click the run command button it only runs the first two parts of the command "py project.py" what only loads the python script and doesn't do any of the commands but I need it to run the full command.

Example Of Code at: https://pastebin.com/hDDjSDVh
 
Share this answer
 
Comments
Richard Deeming 29-Apr-20 11:07am    
If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution and add a comment.

Do not post your comment as a new "solution" to your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900