Problem with a code and passing an array to a function

djsfantasi

Joined Apr 11, 2010
9,156
Why don’t you directly invoke the command processor?

cmd /C x.exe

This starts a command processor, runs x.exe and then terminates.
 

Thread Starter

ArakelTheDragon

Joined Nov 18, 2016
1,362
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

char StartProgmrasFromAList (char InputFileName[5000])
{
  char a[50]="start ";/*comand text example: system("explorer /start,C:\\Windows\\notepad.exe");*/
  char b[5000];

  unsigned int i=0;  /* Counter. */
  /* Chars. */
  FILE *ifp; char *InMode="r";/*Files.*/

  ifp = fopen(InputFileName, InMode);

  if (ifp == NULL)/* This checks the filename for existence/permissions and displays the down message if there is an error with them. */
  {
  printf("The file doesn't exists or doesn't have the right permissions!");
  return '9';
  }

  for(i=0; (fgets (b, 5000, ifp))!=NULL; i++)
  {
  strcpy(a, b);
  /* Main block. */
  printf("%s", b);/* For testing only. */
  system(a);
  /*return fgetc(ifp);*/
  }
  return 0;
}
EDIT:
I also tried "start """.
 

spinnaker

Joined Oct 29, 2009
7,830
Tray this.

Create a batch file. Here is a sample
start /SEPARATE C:\Windows\notepad.exe
start C:\Windows\notepad.exe
start C:\PROGRA~1\Google\GOOGLE~1\client\googleearth.exe

You can get the 8.3 file name by doing a dir /x

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

void main()
{
   


   
   system("test.bat");


   



}
I don't think your program can spawn more than one program at time. You might be able to do it by creating multiple threads.
 

spinnaker

Joined Oct 29, 2009
7,830
This also works but google earth does not launch till the second noetpad is closed.

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

void main()
{
   char buffer[256];
   FILE * fp;
   fopen_s(&fp,"test.txt", "r");


   while (!feof(fp))
   {
     fgets(buffer,strlen(buffer),fp);
     system(buffer);


   }



   fclose(fp);



}
[\code]

test.txt
start C:\Windows\notepad.exe && C:\Windows\notepad.exe && C:\PROGRA~1\Google\GOOGLE~1\client\googleearth.exe
 

402DF855

Joined Feb 9, 2013
271
"explorer /start," is unnecessary but doesn't appear to cause problems.

I copied c:\windows\system32\notepad.exe to my temp directory and it didn't like being executed there; probably some DLL needs to be co-located.

The following code opens four instances of calc.exe without waiting. (Yeah, it's C++ but the C equivalent should work the same.)
C:
//              I DON'T KNOW WHY THIS DOESN'T AUTOFORMAT
void DoTest()
{
FILE *input = fopen("c:\\temp\\x y\\x.lst","r");
CString t;
CStdioFile in(input);
for(;;)
if (!in.ReadString(t))
break;
else
system(t);
fclose(input);
}

Code:
// x.lst
start "" "C:\temp\x y\calc.exe"
start "" "C:\temp\x y\calc.exe"
start "" "C:\temp\x y\calc.exe"
start "" "C:\temp\x y\calc.exe"
 
Top