Link to home
Start Free TrialLog in
Avatar of pdi656
pdi656

asked on

Command prompt output in Win CE

I'm working on a VB.NET program for a Windows CE device. In part of the program I want to open a console program, pass it an argument and read the output. The below code works perfectly in a standard Windows Form program, but will not work in the Windows CE environment.

    Public Function GET_PW_CS(ByVal stIN As String) As String

        'INPUTS: stIN = the argument (passkey) for the  string desired
        'OUTPUTS: The string from the console program

        'Set up the Process
        Dim pInfo As New ProcessStartInfo()
        pInfo.FileName = "C:\MyConsoleProgram.exe"
        pInfo.Arguments = stIN
        pInfo.RedirectStandardOutput = True
        pInfo.UseShellExecute = False
        pInfo.CreateNoWindow = True


        'Calls the program and gets the output
        Dim p As Process = Process.Start(pInfo)
        GET_PW_CS = p.StandardOutput.ReadLine()
        p.WaitForExit()

        pInfo = Nothing
        p.Dispose()

    End Function

Open in new window


These lines aren't recognized as being valid in CE:

pInfo.RedirectStandardOutput = True
pInfo.CreateNoWindow = True
 GET_PW_CS = p.StandardOutput.ReadLine()

Any suggestions? Perhaps there is a completely different way to accomplish this?

Thanks in advance
Avatar of hjgode
hjgode
Flag of Germany image

As Windows CE has only very limitted resources the tools, runtimes and applications have been stripped down. So Compact Framework only and native C API supports only a subset of what is available in full framework and desktop windows.

Although Windows CE offers a command prompt, there is no API to redirect stdin, stderror and stdout back to compact framework.

You need to workaround this if you need to cpature the output of an console app. >ou can redirect output to a file and then in your code wait until the console process has terminated and then read the file.

See also: http://msdn.microsoft.com/en-us/library/aa453925.aspx
Avatar of pdi656
pdi656

ASKER

I set up my console app to write the output to a file. I then tried calling the console app from my program, but it errors out when trying to run the console app. The console app is on our internal network, as is the text file. For some reason it doesn't like executing my command prompt from the network. When I copy the command prompt to the mobile device itself and call it from there I get a MissingMethodException error.

All I'm trying to accomplish is that I'm trying to dynamically get a database connection string for the software on the mobile device to use. We will be moving several database servers over the next few months. Because the connection strings are coded into the software, the only way for the devices to work properly is if I re-install the software on each device on the day of the server switch. My thinking is that if the program dynamically looks up the connection when the software starts, the servers can be moved anytime and all I have to do is change the connection string in one spot (the console program).

If there is another way to accomplish this, I'm open for it.
ASKER CERTIFIED SOLUTION
Avatar of hjgode
hjgode
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdi656

ASKER

Great suggestions. Sounds like I should have hired you to set all of this up in the first place! I thought about storing it in the registry, but I wasn't sure how I'd be able to change it remotely. I didn't want it in a file as I was worried that someone would see it. Not that they couldn't get into the registry, but they are less likely to there.

These devices have barcode readers on them. I may simply send the updated data in the form of a barcode and have the user scan it into a utility in my program that will update the connection string in the registry - a combination of two of your suggestions. I'm still going to explore some of your other suggestions too. Thanks for the ideas!