tags:

views:

58

answers:

2

Currently my application takes in a text file/files, parses them into another file type and puts them on disk. I then call a secondary program (not mine) to process THAT text file into a third.

The foreign program basically does one thing:

program.exe --input:foo.txt --output:bar.txt

What I would like to know... could I replace the foo.txt and bar.txt with string[] in my "object".

Instead of pulling the information from the text file, and putting out into a new text file... I want to pull the info from the variable I have... into another variable I would make.

Basically I'm trying to save the process of creating two stacks of files via piping out of one variable into another. I'm just unsure of how to go about it.

What I have now (For the most part, with some fluff removed):

public bool _Out_Schema(string output)
{
    clear(output);                                      // clear output directory

    // Assign schema name to path
    string path = output + '\\' + lf.filename + ".schema";
    using (StreamWriter SW = new StreamWriter(path))
    {
        SW.Write(lf._schema);
    }                
    return true;
}

public bool _Out_UFD(string input, string output)
{
    clear(output);                                      // clear output directory

    ProcessStartInfo SI = new ProcessStartInfo();
    SI.CreateNoWindow = true;
    SI.WindowStyle = ProcessWindowStyle.Hidden;
    SI.FileName = "ufdschema.exe";                      // foreign program

    SI.Arguments = String.Format("--ischema={0}\\{2}.schema --oufd={1}\\{2}.ufd", input, output, (FI.Name.Split('.'))[0]);
    using (Process P = Process.Start(SI)) { P.WaitForExit(); }

    return true;
}

I'd like to take the lf.schema (string variable) as an input... and create something like lf.ufd as an output

A: 

If program.exe is expecting to read and write to files on disk, and is taking the names of those files via its command line you can't do any funky redirection to make it otherwise.

If the app has other parameters you can set to tell it to take input piped in and to return its output to the console, rather than a file, then you should be able to do something. Based on the details currently in your question, you're probably out of luck though.

Rob
A: 

If the program doesn't have a way to specify "read from stdin and write to stdout", you can't easily solve your problem. It is possible to do, however, but it will require some pretty lowlevel stuff; basically you'd use something like Detours to hook CreateFile, and make it attach to pipes when it sees special filenames. ReadFile, WriteFile and CloseHandle don't need redirection, since they work with pipes as well as file handles.

This is a non-trivial solution, but if you have Win32 API experience it's doable within a couple of hours even if you have no prior knowledge of Detours.

snemarch
I'll have to research if the program can accept arguments like that... I don't think it can. Ultimately, I may have to re-engineer the functionality of it... Although I had hoped to avoid that.
WernerCD
Looking at Detours... the normal version is 32bit. If the external file is 32bit... but I'm compiling / running on 64bit... hrm...
WernerCD
@WernerCD - OS shouldn't matter, as long as the app you want to intercept is 32bit. Iirc there's some non-MS library around somewhere for similar stuff which supports 64bit, but the name escapes me right now.
snemarch
I've looked into Detour and Easyhook. They look a little more involved and a have a little bit bigger learning curve than what I wanted to work with... still looking at both of em.
WernerCD