| | |
sytem woes
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hullo,
I'm trying to make a write a program to automatically create a jar file in java. I've got this far and this works.
But I was wondering is there a better way, using windows API to execute the system("javac Saluton.java") command?
I'm trying to make a write a program to automatically create a jar file in java. I've got this far and this works.
C Syntax (Toggle Plain Text)
#include <windows.h> #include <direct.h> #include <fstream> using namespace std; int main() { chdir("C:/j2sdk1.4.2_04/bin"); system("javac Saluton.java"); system("java Saluton"); remove ("Saluton.class"); return 0; }
But I was wondering is there a better way, using windows API to execute the system("javac Saluton.java") command?
Search for CreateProcess
in the Platform SDK Documentation or MSDN site.
Edit:
Okay here it is.
•
•
•
•
Originally Posted by Platform SDK
BOOL CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
Edit:
Okay here it is.
バルサミコ酢やっぱいらへんで
•
•
•
•
Originally Posted by iamthwee
I have no idea what that means. Seeing as you have taken the time to learn the msdn manual by heart do you think you could code up a sample snippet. :cheesy:
•
•
•
•
Originally Posted by iamthwee
Or is using system() ok here?
system. The overhead for the system call is nothing compared to the effort required to understand and use the CreateProcess function. I would use CreateProcess only if there are some intricate attributes that need to be set in the child processes. But there will be people here who would complain vehemently on the use of system. バルサミコ酢やっぱいらへんで
Ah, just noticed your edit...
This works although I need to wrap it up into a function:
>But there will be people here who would complain vehemently on the use of system.
Yeah I'm kind of in two minds as to whether or not to just use system here. Mmkay.
This works although I need to wrap it up into a function:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <direct.h>
int main( )
{
chdir("C:/j2sdk1.4.2_04/bin");
STARTUPINFO si;
PROCESS_INFORMATION pi;
LPTSTR szCmdline=_tcsdup(TEXT("javac Saluton.java"));
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
szCmdline, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
getchar();
//return 0;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
getchar();
}>But there will be people here who would complain vehemently on the use of system.
Yeah I'm kind of in two minds as to whether or not to just use system here. Mmkay.
![]() |
Similar Threads
- LCD vs CRT (Monitors, Displays and Video Cards)
- Web design table woes (HTML and CSS)
- Virus alert! icon in sytem try maybe spyfalcon (Viruses, Spyware and other Nasties)
- Google PR (Search Engine Optimization)
- IE Woes (Web Browsers)
Other Threads in the C Forum
- Previous Thread: bitwise operations in C
- Next Thread: Dynamic Programming
Views: 1306 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char command convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic executable fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






