简体   繁体   中英

How to share information with a new process (besides the command-line arguments)?

I'm starting a new process with:

process.Start();

I know I can pass strings to it using:

process.StartInfo.Arguments = ...

But I want to share more than just a couple of simple strings – a byte array etc. How do I do that?

EDIT: This is going to be installed as a ClickOnce application, so I don't really know where it will be installed in the file system, and I want to keep it as simple as possible so no files will remain after an uninstall. So where do I put this data?

Take a look at memory mapped files - they allow you to share data between processes.

Alternatives are regular files, the registry, communicating over sockets and more.

If the array is small you can just base64 encode it. Other options consist of saving data to the file or using named pipes

You may want to use Anonymous Pipes .

Anonymous pipes offer less functionality than named pipes, but also require less overhead. You can use anonymous pipes to make interprocess communication on a local computer easier. You cannot use anonymous pipes for communication over a network.

You can create a temp file, write all required data into it and send result file name as a command line argument. When the second application run it will read the content of file and delete it.

if you can encode the byte array properly (eg base64), you can redirect stdin of the target process and stream it through that:

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardinput.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM