How so?
The problem before was not the blank spaces.
Yes the other problem was the double \\ in the input file which I pointed out and then it seems like you completely changed the file name and never mentioned it.
How so?
The problem before was not the blank spaces.
I added a second file, I did not change it. The single dash does not work, it has to be double dash. Thanks Raymond, I tried that before, it did not work. Do you have a solution for the blank spaces in the path?
I have to agree with @spinnaker, it is hard to understand what you are trying .I added a second file, I did not change it. The single dash does not work, it has to be double dash. Thanks Raymond, I tried that before, it did not work. Do you have a solution for the blank spaces in the path?
Apparently the TS solved his problem and is now on to a different one. Never said the game was changed till after the fact. The new problem is the classic space in the command line. Which I do not think is a pobelm any longer with Windows 10 so this must be a pre Windows 10 OS, unless the system function is the one that does not like spaces. The command line just simply needs to be surrounded by quotes when there are spaces.I have to agree with @spinnaker, it is hard to understand what you are trying .
You know that the declaration is int system(const char*command)
You can't change the pointer but you can change the contents of where it is pointing.
I don't know what you mean...anything that I can think of that will work with system("whatever command"), will work by building that string in a.
When you say, "char a[5000] ="explorer /start,C:\\Windows\\notepad.exe";" it works AND it is \0 terminated, you need to build that - explorer /start,C:\\Windows\\notepad.exe - exactly and terminate it with a \0 in the array and don't add the \n that fgetc is adding (it must, right, because you are scanning for it.
That is a problem with code that you posted as I am seeing it - have you moved on to something else?
ughApparently the TS solved his problem and is now on to a different one. Never said the game was changed till after the fact. The new problem is the classic space in the command line. Which I do not think is a pobelm any longer with Windows 10 so this must be a pre Windows 10 OS, unless the system function is the one that does not like spaces. The command line just simply needs to be surrounded by quotes when there are spaces.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
char main()
{
char a[500]="explorer /start,";/*comand text example: system("explorer /start,C:\\Windows\\notepad.exe");*/
char b[5000];
unsigned int i=0,z=0; /* Counter. */
char c;/* Chars. */
FILE *ifp; char InputFileName[]="Files.t"; 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 dialog was canceled by the user, the file doesn't exists or doesn't have the right permissions!");
return -9998;
}
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);*/
}
}
Ok great, looks like you have it all sorted out. Now, if you want, you could print out the bytes in a[] before strcpy and after right before you do the system().I tried null terminating the array, ti does not work, if its hard coded it works, if its read from a file it does not work. That problem was solved by using "strcpy()" which for some reason is ok. Now the problem is the spaces in the path, the idea is to read 1 path and start it, read a second and start it and so on. So the path has to be "Path". This is all, it worked now. New code:
Ok, you’re right. I mistakenly assumed the full path WAS specified as the program name.I don't think the program name is enough. You neeed the path and the name if its not in the environmental variables. I will check the reference, thanks for the help!
Ok, next problem, now the programs get started 1 by 1, I have to close the previous one for the new one to open. Thanks for the "Progra~1" it works better.
No, that part is not in the previous code and yes, I did read the previous posts, including line 27 in the code. If you had understood my post, what I said was to print it out byte by byte, before and after as a debugging aid because printf is not going to, necessarily, tell you any non-printable characters.That part is already in the code, you can see it at line 27. You don't read the previous posts .
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
UART/CODE problem Oshonsoft | Microcontrollers | 72 | ||
3D printer G-code problem | General Electronics Chat | 3 | ||
S | [SOLVED] problem with IAR code | Programming & Languages | 7 | |
Problem Uploading code in Custom Board Atmega328P U-TH | Microcontrollers | 14 | ||
dsPIC33CH I2C code syntax problem (SOLVED) | Microcontrollers | 25 |
by Jake Hertz
by Jake Hertz
by Jake Hertz
by Jake Hertz