I want to execute a command to query DHCP Server. For that purpose I have written some code in perl. Now when I execute that perl file in command prompt using c# I get following errer "The specified executable is not a valid Win32 application." I have pasted the code below. Can anybody please suggest what could be the possible reason of this error message.

System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.WorkingDirectory = "c:\\Windows";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.FileName = "lease_query.pl";
            p.StartInfo.Arguments = "perl lease_query.pl " + ipAddress;

            p.StartInfo.CreateNoWindow = true;

            p.Start();
            p.Close();

Thanks,
Jamal

Recommended Answers

All 4 Replies

You might need to specify the full path in p.StartInfo.FileName = "lease_query.pl"; .
E.G. p.StartInfo.FileName = "c:\\MyApps\\lease_query.pl";

Actually I think the FileName and Arguments mixed up because the final command yours is running would look like
C:\>lease_query.pl perl lease_query.pl 192.168.0.100
and lease_query.pl is not an executable.

so i think it should be.

p.StartInfo.FileName = "perl";
p.StartInfo.Arguments = "lease_query.pl " + ipAddress;
commented: I didn't see that. Well spotted. +1

Thanks OTS=G-Man

You solved my issue.

Cheers

Glad to have helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.