ShellExecute and file output

  • Thread starter Thread starter fdmaxey
  • Start date Start date
F

fdmaxey

I currently start a target executable written in VB.Net from an
application that uses a C-script language.

I start the target executable using ShellExecute in the C-script. The
target runs fine like this except for the fact that the target can't
write to a log file. If I run the target independently of the C-script
application, the log file is created and written to without a hitch.

There is no error produced - the log file just never appears. If I put
a log file in the directory, it is not appended.


The code is as follows:

Dim tx as TextWriter = File.AppendText("Log.txt")

tx.WriteLine( sLogText )

tx.Close


The ShellExecute command is:

result = ShellExecute(
HWND_DESKTOP, "open", "target.exe", "-1", NULL,
SW_SHOWNORMAL);


I get the impression I'm missing something simple here, but I don't know
what it is.

TIA

Frank Maxey
 
fdmaxey said:
I start the target executable using ShellExecute in the C-script. The
target runs fine like this except for the fact that the target can't
write to a log file. If I run the target independently of the C-script
application, the log file is created and written to without a hitch.

There is no error produced - the log file just never appears. If I put
a log file in the directory, it is not appended.
[...]
Dim tx as TextWriter = File.AppendText("Log.txt")
[...]
result = ShellExecute(
HWND_DESKTOP, "open", "target.exe", "-1", NULL,
SW_SHOWNORMAL);

Try passing the working directory (e.g., the application's directory)
instead of passing 'NULL' in the 'lpDirectory' parameter.
 
Dim tx as TextWriter = File.AppendText("Log.txt")

Since you're using a relative file path the file will opened from the
current directory, which may differ depending on how you run the
application. Make sure Environment.CurrentDirectory is what you expect
it to be.



Mattias
 

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

Back
Top