|
 |
|
 |
07-25-2003, 12:29 PM
|
#1 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,475
|
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
|
|
|
07-25-2003, 01:13 PM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
|
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
|
|
|
07-25-2003, 01:47 PM
|
#3 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,475
|
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
|
|
|
07-25-2003, 02:51 PM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,475
|
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
|
|
|
07-25-2003, 03:29 PM
|
#5 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
|
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..
|
|
|
07-25-2003, 05:22 PM
|
#6 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,475
|
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
|
|
|
07-25-2003, 07:43 PM
|
#7 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
|
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.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
|
c++.net console app ?
|
sde |
Standard C, C++ |
5 |
03-13-2003 06:07 AM |
All times are GMT -8. The time now is 07:36 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|