Running external program...

G

Greg

I'm trying to run an external command-line file converter from a Windows
Service but it's not working. If I run it from a normal app it works fine.
I am able to run other EXEs from my Windows Service without any problems. I
think this problem is related to the capturing of the result.

Basically, the converter is an Excel document converter. I use the greater
than sign to capture the result to a file because it simply writes to the
screen. The file always ends up empty when called from the Windows Service,
but works fine when called from a normal app.

Here's what I'm doing:

xlhtml.exe c:\test.xls > c:\test.txt

Code:

Process.Start("cmd.exe", "/c c:\xlhtml.exe c:\test.xls > c:\test.txt")

I also tried it using the System.Diagnostics.ProcessStartInfo way.

Is there anything I can do to get this to work?
 
G

Greg

Greg said:
I'm trying to run an external command-line file converter from a Windows
Service but it's not working. If I run it from a normal app it works fine.
I am able to run other EXEs from my Windows Service without any problems. I
think this problem is related to the capturing of the result.

Basically, the converter is an Excel document converter. I use the greater
than sign to capture the result to a file because it simply writes to the
screen. The file always ends up empty when called from the Windows Service,
but works fine when called from a normal app.

Here's what I'm doing:

xlhtml.exe c:\test.xls > c:\test.txt

Code:

Process.Start("cmd.exe", "/c c:\xlhtml.exe c:\test.xls > c:\test.txt")

I also tried it using the System.Diagnostics.ProcessStartInfo way.

Is there anything I can do to get this to work?

I figured out the problem.
 
T

thunder$truck

In order to run shell applications from a cmd prompt you must first
call the proper environment

ex: Shell(Environ("COMSPEC") & " /k psexec \\" & CompHost
& " ipconfig /all"

This line calls the cmd prompt to run
c:\>psexec \\<machineNameOrIPAddress> ipconfig /all

It's exactly the same as using the cmd prompt so you'll have to
respect the limitations (no spaces, etc)

The /k switch tells my application to leave the prompt open so I can
examine the results... a /c switch would close the shell environment
as soon as it's operation had completed..

T$
 
G

Greg

Herfried K. Wagner said:
What was the problem?

I wasn't able to use Process.Start. I had to use
System.Diagnostics.ProcessStartInfo and create a .bat file. In addition to
that, it only worked when I set the WorkingDirectory to the directory with
the .bat file.
 
M

Mike Ouimet

Hi, I am trying to do something similar to what you were attempting. The
differance is I am trying to run a netstat command via the psexec tool
all from within a vbscript. I am using the WScript.Shell to execute the
following command and when I do I get the error below. Any thoughts
would be greatly appreaciated!

Command:
Const command_exec = "psexec.exe"
cmdNetStat = "netstat.exe -a | find /C " & Chr(34) & ":33569" & Chr(34)
strPath = cmdNetStat
Set objExec = objWshShell.Exec (strPath)

Error:
netstat.exe exited on ServerName with error code 1.

Michael Ouimet


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top