Hi,
Using Process class I asynchronously launch an executable (black box
executable) file from my Windows application. I mean asynchronously
because I've got an EventHandler for "Exited" event. Therefore, when
process finishes, "Exited" event is raised.
This executable writes a long file for over 1-5 minutes, and I, from
my application must read that file while is being generated.
Therefore, after launching the executable calling "Start()" method, I
initialize a timer which tries to read from the file every 20 seconds
for example.
The result is that when trying to read for the first time, process
exits and I need the process to continue executing. I thought it was
because of reading the file simultaneously (file sharing violation),
but if I try just to show a message, occurs the same. Process exits
always.
Then, which would be the best way to read a file that is being
written? Maybe threads? A FileSystemWatch er? Is it possible?
Thanks very much in advance. 8 3210
"Lonifasiko " <ml*******@gmai l.comwrote in message
news:11******** **************@ w1g2000hsg.goog legroups.com...
Hi,
Using Process class I asynchronously launch an executable (black box
executable) file from my Windows application. I mean asynchronously
because I've got an EventHandler for "Exited" event. Therefore, when
process finishes, "Exited" event is raised.
This executable writes a long file for over 1-5 minutes, and I, from
my application must read that file while is being generated.
Therefore, after launching the executable calling "Start()" method, I
initialize a timer which tries to read from the file every 20 seconds
for example.
The result is that when trying to read for the first time, process
exits and I need the process to continue executing. I thought it was
because of reading the file simultaneously (file sharing violation),
but if I try just to show a message, occurs the same. Process exits
always.
Then, which would be the best way to read a file that is being
written? Maybe threads? A FileSystemWatch er? Is it possible?
Thanks very much in advance.
Im doing the same thing with streamwriter and streamreader from 2 different
applications,
with no problems you just have to make sure the writer opens it with
share=read.
although the two executables are luanched independantly.
In my app if the stream reader reaches EOF it just sleeps, and retries again
later.
I think you must have some other problem if reading cuases the writing app
to exit.
Colin =^.^=
By default, the System.IO.File. Open method attempts to open a file
exclusively. You can use the overload which takes a parameter of a FileShare
enumerated value (File.Open Method (String, FileMode, FileAccess,
FileShare)) to open it differently, allowing other threads and process to
access the file. See http://msdn2.microsoft.com/en-us/lib...fileshare.aspx for the
complete FileShare enumeration documentation.
Note that, since the default is exclusive, BOTH threads must use the
overloaded method. The second thread must use something like the following,
if the file is already opened for writing:
FileStream fs = new FileStream("C:\ foo.txt", FileMode.Open,
FileAccess.Read , FileShare.ReadW rite);
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries: http://www.miradyne.net
"Lonifasiko " <ml*******@gmai l.comwrote in message
news:11******** **************@ w1g2000hsg.goog legroups.com...
Hi,
Using Process class I asynchronously launch an executable (black box
executable) file from my Windows application. I mean asynchronously
because I've got an EventHandler for "Exited" event. Therefore, when
process finishes, "Exited" event is raised.
This executable writes a long file for over 1-5 minutes, and I, from
my application must read that file while is being generated.
Therefore, after launching the executable calling "Start()" method, I
initialize a timer which tries to read from the file every 20 seconds
for example.
The result is that when trying to read for the first time, process
exits and I need the process to continue executing. I thought it was
because of reading the file simultaneously (file sharing violation),
but if I try just to show a message, occurs the same. Process exits
always.
Then, which would be the best way to read a file that is being
written? Maybe threads? A FileSystemWatch er? Is it possible?
Thanks very much in advance.
Hi,
As I mention in my first post, the executable I'm launching it's a
black box for me, that is, I don't know how opens the file for writing
(exclusive mode or not). To make my work harder, I'm sure executable
opens the file for writing in exclusive mode.
Then, when trying to read the file being written, I'm using the very
confortable File.ReadAllLin es(filepath) method, which does not give me
any possibility of opening the file using FileShare and FileAccess
attributes.
Any more ideas?
Thanks very much.
It's me again,
Just one question: If the black box executable I use opens the file
for writing purposes in exclusive mode, do I have any possibility of
reading it while black box executable is writing inside?
If not, I should tell black box executable developer as soon as
possible....
Thanks very much.
"Lonifasiko " <ml*******@gmai l.comwrote in message
news:11******** *************@y 5g2000hsa.googl egroups.com...
It's me again,
Just one question: If the black box executable I use opens the file
for writing purposes in exclusive mode, do I have any possibility of
reading it while black box executable is writing inside?
If not, I should tell black box executable developer as soon as
possible....
well thats the purpose of exclusive mode to stop other processes opening it,
when you open a streamreader you can open it with a string=path/filename
wich doesnt let u set share mode,
but you can also open it with
StreamReader sr=new StreamReader(ne w
FileStream(path ,FileMode.Open, FileAccess.Read ,FileShare.Read Write));
wich lets you set the share mode etc.
Colin =^.^=
Hi,
Thanks for the replies. I'm still having many problems.
I think problems come from executing the executable asynchronously.
After launching executable with "Start()", next thing I do is to check
if executable has generated file. If so, it should start reading the
file.
Yesterday tried starting a timer that checks the generated file each
30 seconds and also tried adding a FileSystemWatch er in order to see
when the generated file is created, or changes, but this two
approaches do not work; they only make the executable process to
terminate. I understand these processes interfere the work of
asynchronous Process class and that's why terminates.
I would really appreciate nay more help. Thanks very much in advance.
Hi again,
I wanted to sum up in this new post my last discoveries ;-)
If I launch the executable in asynchronous mode, without doing nothing
more, the output CSV file is generated without problems.
Then, I add a button to my form and inside "Click" event, I just check
if file has been generated. Generated or not, I write some text in a
textbox. All this also launching the process in asynchronous mode.
Well.....does not work! Incredible but true!
I've also noticed black box executable generates a temporary file and
when finished its execution, renames this temporary file with the
definitive filename (filename I check in my "Click" event). Anyway,
although inside my "Click" event will never see the file I'm looking
for, there should not be any problem in writing just "File does not
exist" in a simple textbox. Even this does not work!
I'm really desperated with this issue.
Maybe starting a thread that checks (and reads) the output file would
do it?
Thanks for your patience.
Forget to tell you that I've built a little example in which I launch
asynchronously an executable that writes a file inside an infinite
loop.
Then, in the "click" event of a button, I try to read using
StreamReader sr=new StreamReader(ne w
FileStream(path ,FileMode.Open, FileAccess.Read ,FileShare.Read Write));
as Colin said. This works!
I'm able to read the file being written!
What do you think? Black box executable related?
Regards. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve |
last post by:
I need help. I'm trying to write a process wrapper class in Python (on
Linux) that let's one:
- read service definitions from a config file (where a service definition
includes a bash command to start the service, and the service is a daemon)
- call a method that will start up the service
- call a method that will shut down the service.
- other stuff not relevant here
Where I'm stumped is in starting up the service in a way that:
-...
|
by: yyii |
last post by:
Hi,
I have a problem on retreiving the status of the child process. I want to
open IE and load local file. Just after it is loaded, I need to delete that
local file. It seems that I can't use the function
WaitForInputIdle/WaitForSingleObject in this situation. Please advise how I
can be notified once the IE is completed reading the file. Many thanks!
STARTUPINFO si;
PROCESS_INFORMATION pi;
|
by: Al Cohen |
last post by:
I'll start by warning that I'm a newbie to C# (but I've been programming
for 25 years), so I may just be doing something reallyreally dumb.
I'm writing a C# wrapper for a command-line application (pscp.exe, a
secure file-copy app that's part of the excellent PuTTY SSH package).
Getting pscp.exe to run properly was a piece of cake using the
System.Diagnostics.Process class.
The thing that I can't get to work is the ability to read...
|
by: trellow |
last post by:
Hello,
I am writing an application that needs to read a file that is already open by another process for writing.
When I do the following:
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
I get the following exception:
|
by: Raed Sawalha |
last post by:
Hello , I have windows service which do listening to specified directory
using FileSystemWatcher , on Created Event and Get all the files in the
directory using Directory.GetFiles function then foreach file in the files
list and passed the file path to a function to read its content then process
it then move it to another directory
am reading each file content using StreamReader...ReadToEnd function, all
process working fine , That when 50...
| |
by: Steve |
last post by:
I am using Diagnostics.Process to, well.. execute a process. I would like
to display the output of the process to my UI as it is created. For
example, ping www.yahoo.com will slowly output each result. I want to
display that output as it happens in my UI.
I don't see a clean way to do this. After my Start() call, I made a call to
StandardOutput.ReadToEnd() but it appears to hang until the process finishes
(makes sense) But what do...
|
by: Eran.Yasso |
last post by:
Hi,
My app starts process. Some times this process exits because of
exception. Can my app know if the process exited due to exception or
gracefully?
In both ways, the exit code of this process is zero.
I tried using the following, but it goes to catch.
|
by: John Halet |
last post by:
I have a application that crunches a bunch of data, creating log
files, excel files etc...
I use Process.Start to open any number of these file for viewing.
My goal is to have the application close all the file it opened when
the it exits.
I start files like this for example:
Dim myProcess As Process =
System.Diagnostics.Process.Start("LatestData.xls")
|
by: Samuel A. Falvo II |
last post by:
I have a shell script script.sh that launches a Java process in the
background using the &-operator, like so:
#!/bin/bash
java ... arguments here ... &
In my Python code, I want to invoke this shell script using the
Subprocess module. Here is my code:
def resultFromRunning_(command):
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |