Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Systems > Windows

Reply
 
LinkBack Thread Tools Display Modes
Old 07-25-2003, 01:29 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
quick & dirty app for xp

i just need to make a program that would be the equivalent to changing a directory and executing a command.

i ONLY have is .NET stuff ( c++, VB, & C# ) and it needs to be able to run on Windows XP without the .NET framework.

it definately needs to be a .exe file so the source can not be edited.

any advice for a quick solution and me not having to go buy some other c++ software?
__________________
Mike
sde is offline   Reply With Quote
Old 07-25-2003, 02:13 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
You want the code for it? or what??
Code:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
  int ret=0;
  if(argv != 3)
  {
     printf("Usage %s [directory] [program]\n", argv[0]);
     return -1;
  }
  if(!chdir(argv[1]))
     if(!(ret=system(argv[2])))
        return 0;
     else
     {
        printf("Failure executing %s\n", argv[2]);
        return ret;
     }
  else
  {
     printf("Failure changing to %s\n", argv[1]); 
     return -1;
  } 
}
Or do yu want a more complex code, where you dup(), fork(), write(), read() and waitpid() for the program execution. So you capture everything your external execution does.

Can't .NET compile to something like a [selbstendiger/Selvstændig] app, sorry can't remember the english name..
Else get Cygwin
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 07-25-2003, 02:47 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
i guess if you are not referencing any of the .net framework, then it doesn't have to be installed on the machine running your code.

thanks for the code, but i hacked out something very simple .. i just needed to register a .dll file

Code:
# include <iostream.h>
# include <windows.h> 
 
int main()
{  	
  system("regsvr32 \"C:\\Program Files\\program\\file.dll\"");
  
  return 0;
}
now i want to build in some errors in case that their install directory was different than the default path.

thanks for the input =)
__________________
Mike
sde is offline   Reply With Quote
Old 07-25-2003, 03:51 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
i want this app to catch the exceptions it throws out when it can't find the dll , or the dll successfully registers .. but i'm too n00b to know where to start.

if it can't put find the dll, i'd like to allow the user to define the path to the file.

is there any quick reference on how to do this?

this is more for learning at this point .. nothing too important now that the main function works .. as un-graceful as it is.
__________________
Mike
sde is offline   Reply With Quote
Old 07-25-2003, 04:29 PM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Quote:
Originally posted by sde
i want this app to catch the exceptions it throws out when it can't find the dll , or the dll successfully registers .. but i'm too n00b to know where to start.
Code:
#include <stdio.h>
# include <windows.h> 
#include <unistd.h>

int main()
{
   int ret=-5;
   if(!access("C:\\Program Files\\program\\file.dll", F_OK))
      ret=system("regsvr32 \"C:\\Program Files\\program\\file.dll\"");
   switch(ret)
   { 
     case -5:  
       printf("Dll file does not exist\n");
       return -1;
     case 0:
       printf("Successful return\n");
       return 0;
     default:
       printf("system call returned with errno: %s\n, WEXITSTATUS(ret));
       return ret;
   }
}
Quote:

if it can't put find the dll, i'd like to allow the user to define the path to the file.
Dont know if there is any way to get a dialogue with the user without some interaction from the lower level runtime machine in .NET, else just make it a dos like app, asking on stdout and reading from stdin..
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 07-25-2003, 06:22 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
Quote:
[C++ Error] cwfix.cpp(8): E2268 Call to undefined function 'access'
[C++ Error] cwfix.cpp(8): E2451 Undefined symbol 'F_OK'
[C++ Error] cwfix.cpp(19): E2380 Unterminated string or character constant
[C++ Error] cwfix.cpp(20): E2121 Function call missing )
i installed borland 5 and when i compile this, i get the errors above. seems like i'm missing an include which contains the 'access' function.
__________________
Mike
sde is offline   Reply With Quote
Old 07-25-2003, 08:43 PM   #7 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
I know access() isn't a strict Ansi C function, In *nix it comes from unistd.h, hence Unix standard, I think in borlan it is called something like file(), and is in a header much like dos.h or something like that.

Quote:
[C++ Error] cwfix.cpp(19): E2380 Unterminated string or character constant
The line:
printf("system call returned with errno: %s\n, WEXITSTATUS(ret));
should be:
printf("system call returned with errno: %s\n", WEXITSTATUS(ret));
And then it'll probably complain about WEXITSTATUS() undefined function... Since this is just a macro trying to give you some hints on the error status from the system call.
ie: 0 success, 1 some minor error, -1 some average error etc.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
c++.net console app ? sde Standard C, C++ 5 03-13-2003 07:07 AM


All times are GMT -8. The time now is 05:45 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting