Welcome, Guest. Please login or register.

Author Topic: Using Execute() in C.  (Read 3082 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline SidewinderTopic starter

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 241
    • Show all replies
    • http://www.liquido2.com
Using Execute() in C.
« on: March 23, 2004, 04:39:32 AM »
I've created a little program to generate simple assembly source files and wish to call the assembler (PhxAss) directly from the C program.  I've found that the Execute() function works nicely for this, but I'm having trouble getting it all the work properly.  Here's the code of my function:

Code: [Select]

#include <exec/types.h>
#include <exec/libraries.h>
#include <dos/dos.h>
#include <proto/exec.h>
#include <proto/dos.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include &quot;assembler.h&quot;

int assemble(char *file_name)
{
struct Library *DOSBase = NULL;

if (!(DOSBase = OpenLibrary(DOSNAME, 0)))
{
printf(&quot;Unable to open dos.library\n&quot;);
return FALSE;
}
else
{
char *command = NULL;
char *assembler_name = &quot;PhxAss&quot;;
char *output_file_name = &quot;file.err&quot;;
BPTR output_file = NULL;

if (!(command = (char *)malloc(sizeof(assembler_name) + sizeof(file_name) + 2)))
{
printf(&quot;Out of memory\n&quot;);
return FALSE;
}

strcat(command, assembler_name);
strcat(command, &quot; &quot;);
strcat(command, file_name);

output_file = Open(output_file_name, MODE_NEWFILE);

printf(&quot;%s\n&quot;, command);

Execute(command, NULL, output_file); /* Call the assembler. */

if (output_file)
{
Close(output_file);
}

CloseLibrary(DOSBase);
}

return TRUE;
}


This seems to work up to a point.  It finds PhxAss which is in the default directory but fails to find the source file in the same directory.  I get the following error in the output:

12 File doesn't exist (Init).
PhxAss failed returncode 20

This is a PhxAss error that means it can't find the file.  I've tried adding the full path to the file name with the same results.

Does anyone have any idea what could be going on?

Thanks.
Sidewinder
 

Offline SidewinderTopic starter

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 241
    • Show all replies
    • http://www.liquido2.com
Re: Using Execute() in C.
« Reply #1 on: March 23, 2004, 05:34:04 AM »
@Doobrey

If the "TO " is left off of the command line then the executable will have the same name as the source file minus the extension.  I have tired it both ways just in case but get the same results.  However, the same command line works fine from a shell.

I haven't used SnoopDOS yet.  I don't have it setup on this machine.  I'll give it a try.
Sidewinder
 

Offline SidewinderTopic starter

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 241
    • Show all replies
    • http://www.liquido2.com
Re: Using Execute() in C.
« Reply #2 on: March 23, 2004, 11:00:53 PM »
Everyone, thanks for the corrections.  I've made them and installed SnoopDOS.  Apparently PhxAss is looking for a file called PHXOPTIONS which I do not havea and I'd really rather not use it.

Here's the SnoopDOS log:

Code: [Select]

SnoopDos logging started on Tuesday, 23-Mar-04 at 16:50:33

Count Process Name       Action     Target Name                 Options Res.
----- ------------       ------     -----------                 ------- ----

 38    [4] PhxAss         Open       prog.s                      Read    OK  
 39    [4] PhxAss         Open       prog                        Write   OK  
 40    [4] compiler       Open       prog.in                     Read    OK  
 41    [4] compiler       Open       prog.s                      Write   OK  
 42    [4] compiler       Open       file.err                    Write   OK  
 43    [4] compiler       Execute    PhxAss &quot;prog.s&quot;             Single      
 44    [3] PhxAss         Open       PHXOPTIONS                  Read    Fail
 45    [3] PhxAss         Open       ENV:PhxAss/PHXOPTIONS       Read    Fail


Closed SnoopDos log at 16:51:24


38 and 39 are from directly calling PhxAss from the command line as:

PhxAss "prog.s"

40 through 45 are the result of running my little compiler.  It doesn't seem to even attempt to open the source but rather looks for the PHXOPTIONS file even though the command line is the same.

Does anyone have any more clues?


Sidewinder
 

Offline SidewinderTopic starter

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 241
    • Show all replies
    • http://www.liquido2.com
Re: Using Execute() in C.
« Reply #3 on: March 23, 2004, 11:32:16 PM »
@ Doobrey

True, this is how I thought it was supposed to work, but if I follow the SnoopDOS output correctly, it never attempts to open the prog.s file, it can't open the PHXOPTIONS file in the current directory or in ENV: and then chokes...it doesn't ever assemble anything.  As far as I can tell the command passed to Execute() is the same one that I run from the DOS prompt, but the results are totally different.  This is crazy.
Sidewinder
 

Offline SidewinderTopic starter

  • Full Member
  • ***
  • Join Date: Mar 2002
  • Posts: 241
    • Show all replies
    • http://www.liquido2.com
Re: Using Execute() in C.
« Reply #4 on: March 24, 2004, 12:14:57 PM »
@Piru

Thanks for the tip on using SnoopDOS.  I found out the the lock was indeed failing.  After a little thought on why a lock might fail I realized that I was calling the assemble function  before closing the file in the calling function. :crazy:  It works now.  Thanks everyone for your help!!!
Sidewinder