Solved

run python script in VB.net

Posted on 2011-02-24
4
2,279 Views
Last Modified: 2013-11-05
I need to run a python script in VB.net.  The script itself works perfectly but will not run when I try to do it withing VB.net.  I get the error "The specified executable is not a valid application for this OS platform."
Label2.Text = String.Empty

        If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
            Dim p As Process = New Process

            txtSD.Text = FolderBrowserDialog1.SelectedPath
            p.StartInfo.FileName = "WinCombineLogs.py" 'set path of current antivirus product.
            p.StartInfo.Arguments = " -d " + DateTimePicker1.Text + " -f " + txtSD.Text 'set arguments of current antivirus product.

            p.StartInfo.UseShellExecute = False 'required for redirect.
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden 'don't show commandprompt.
            p.StartInfo.CreateNoWindow = True
            p.StartInfo.RedirectStandardOutput = True 'captures output from commandprompt.
            p.Start()
            p.WaitForExit()
        End If
    End Sub

Open in new window

0
Comment
Question by:NevSoFly
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Hairbrush earned 500 total points
ID: 34978516
When you run the WinCombileLogs.py file from your command line, Windows will look in your registry to find out what program is associated with the ".py" file extension, and will then pass the filename as a parameter to that program.

Your code tries to call WinCombineLogs.py as if it was a program directly executable by Windows, but that isn't the case.  What you'd need to do is set StartInfo.FileName to the filename of your Python script interpreter, and pass "WinCombineLogs.py" as the first argument.
0
 

Author Comment

by:NevSoFly
ID: 34980794
where would I find the interpreter for Win XP or Win 7?
0
 
LVL 12

Expert Comment

by:Hairbrush
ID: 34981384
As you said that "the script itself works perfectly" I presume you already have the software installed on your PC.  Try looking for C:\Program Files\Python\python.exe

(http://docs.python.org/faq/windows.html#how-do-i-make-python-scripts-executable)
0
 

Author Closing Comment

by:NevSoFly
ID: 35010780
thank you
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question