-5

Good Afternoon Everyone. I have taken on a C# programming assignment that was previously coded by someone else. This program originally called two perl scripts for execution. Those perl scripts were written back in the 90's and basically do a lot of formatting and filtering prior to calling various 8086 executables for assembling and linking .a86 files.

In the beginning I rewrote the perl scripts to increase speed and accept arguments in from the c# program. I am not very good at interpreting some of what the original script was doing.

Now in the C# program I have instantiated processes for all of the executables and am starting them successfully except for when running link86.exe I get errors. The link86 process has the following info:

Process test = new Process();
ProcessStartInfo testproc = new ProcessStartInfo();
testproc.FileName = path + "\\link86.exe";
testproc.Arguments = procData; // procData is a string
test.testproc.Start();

/* I'm having trouble passing all of these objects as arguments 
 * to link86. link86 does not like the '&' being in the string, 
 * also the ' ' (space) is not required between arguments.  After 
 * 6 objects as arguments the command line returns the following error
 * 'The system cannot execute the specified program' it seems as if the
 * the command line is trying to execute the .obj file I don't know why  
 * this is.
 * The error returned by the debugger says the 'Parameter was invalid'
 */ 

procData = (in text visualizer)
file.OBJ, &
file2.OBJ, &
TO outputfile.LNK OPTIONS

procData = (when hovering over object)
"file.OBJ, &\nfile2.OBJ, &\nTO outputfile.LNK OPTIONS"

On the command line the following command works up until I enter a 7th .obj file.
link86 file.obj, file2.obj,...TO outputfile.LNK OPTIONS

I looked up some info about link86.exe and I have found out it has a command line length limit of 127 characters. I am trying to pass about 95 .obj files to link86 as arguments.

If I could find a method to pass 90+ arguments to link86 via c# that would help immensely.

Thanks for your time and consideration in this matter!

Michael Riley
  • 67
  • 1
  • 10
  • See also [Using open() for IPC](https://metacpan.org/pod/perlipc#Using-open-for-IPC). – Sinan Ünür Aug 08 '15 at 01:50
  • Sinan Unur you are correct that there are sort of two questions. Both lead to the same result though. I have been directed to make this program execute all of these tasks in a multithreaded fashion which I did to a point by executing the perl scripts as different processes but the GUI freezes during execution. C# seems to be quite adept at file and string handling so I am not throwing out the perl code but utilizing it's functionality in a new language. I guess what I don't understand about the perl script is what '^&' this sort of stuff does and what $filename| does. – Michael Riley Aug 08 '15 at 02:00
  • Sinan Unur, Thanks for the IPC link, I'm reading it now.... – Michael Riley Aug 08 '15 at 02:06
  • Where is the documentation for `link86`? It may have a command line argument limit, but the Perl script is reading arguments from `$tempfn`. Your multi-threading attempts are probably getting borked because of the fact that all the processes are trying to create the same helper files. For that, you would need to ensure that the Perl script uses distinct auxiliary files for each process. – Sinan Ünür Aug 08 '15 at 02:06

1 Answers1

0

Looking at the Perl part of the question:

open( FILE "link86 ^& < $tempfn|" ) || die "Could not run link86: $!\n";

This is a syntax error. FILE is a bareword filehandle. You need a comma after that for the next argument to open. So, the line should be:

open( FILE, "link86 ^& < $tempfn|" ) || die "Could not run link86: $!\n";

The second argument is a command for the shell to execute. The trailing pipe indicates that the output of the command will be piped to your program via the FILE filehandle.

^& will be interpreted by the shell executing this program. In this case, I am assuming the shell is cmd.exe. ^ is the escape character in cmd.exe. Therefore, it causes the following & to be interpreted as a literal character. (See also, Everyone quotes command line arguments the wrong way: "When cmd transforms a command line and sees a ^, it ignores the ^ character itself and copies the next character to the new command line literally ...")

I am not exactly sure what it does, but it seems to basically execute link86 using the contents of whatever filename is in $tempfn.

while( <LINK> )
{
    print; # what does the print without parameters do?
    if( /^(EXCEPTION|ERROR)/i ) 
    {
        $abflag = 1;
    }
    print $dlogH "\nabort Flag:  $abflag\n";
}

This reads from the LINK bareword filehandle. Each line is stored in $_, and then printed. Without arguments, print prints the contents of $_ to the currently selected output filehandle (most likely STDOUT).

If the line contains either EXCEPTION or ERROR, it sets the abort flag. For each line read from LINK, it prints the value of abort flag. Once set, the abort flag remains set.

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
  • Sorry I forgot the ',' after FILE. So when link86 gets executed does it get the contents of whatever file is in `$tempfn` all at once as in: `link86 file.obj, file2.obj, file3.obj......file95.obj` or are they read in one at a time? I think they all go at once and then link86 is executed because all of the object files need to be linked together. I have been playing with this vai the command line and it seems that link86 needs all of the object files at once. How would I emulate the perl functionality in C#? – Michael Riley Aug 08 '15 at 02:38
  • The invocation `"link86.exe ^& response.file"` is not Perl specific. Piping its output to the Perl program is. [How To: Execute command line in C#, get STD OUT results](http://stackoverflow.com/questions/206323/how-to-execute-command-line-in-c-get-std-out-results) ... The accepted answer gives the output in one go instead of line-by-line, but you should be able to figure out where to go based on that. See also [Process.StandardOutput Property](https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx) – Sinan Ünür Aug 08 '15 at 02:41
  • Thanks so much! I'll get to work and post when I reach a solution! – Michael Riley Aug 08 '15 at 02:51