Windows Execute_shell : syntax ?

E

Erik131313

Guest
Hi,
I want to use execute_shell inside a GMS2 program to open the file mesresultats.txt which is in the following directory C:\Users\Erik\AppData\Local\Test_réseaux_sociaux with Libre Office Writter which is in the directory C:\Program Files\LibreOffice\program\soffice.exe".

What I know is only : execute_shell(command,wait) but how to write command and what is wait ?

I try this but it doesn't work !
execute_shell("C:\Program Files\LibreOffice\program\soffice.exe C:\Users\Erik\AppData\Local\Test_réseaux_sociaux\mesresultats.txt",1);

Is there anyone to help me ?
Thanks
Erik
 
S

Sam (Deleted User)

Guest
ok, so the common misconception here is that the command line can auto detect spaces in file paths. It cannot. You need quotes around each file paths and other kinds of command line arguments that could potentially contain spaces, just like you would need this in command prompt.

otherwise each string divided by spaces will be interpreted as separate command line arguments.

so if that really is the way you open a file in soffice.exe, it may be corrected by doing:
GML:
execute_shell("\"C:\\Program Files\\LibreOffice\\program\\soffice.exe\" \"C:\\Users\\Erik\\AppData\\Local\\Test_réseaux_sociaux\\mesresultats.txt\"",1);
wait is whether the game should not process any events and remain paused while the program you executed remains opened.

The above code is for GMS2. For GMS1.4:
GML:
execute_shell('"C:\Program Files\LibreOffice\program\soffice.exe" "C:\Users\Erik\AppData\Local\Test_réseaux_sociaux\mesresultats.txt"',1);
 
Last edited by a moderator:
E

Erik131313

Guest
Hi,
Thank you for your response.

No error occurs when I run my GMS2 program but nothing appends.
I have tried with soffice.exe and after with wordpad.exe without success. Nothing appends.

// execute_shell("\"C:\Program Files\LibreOffice\program\soffice.exe\" \"C:\Users\Erik\AppData\Local\Test_réseaux_sociaux\mesresultats.txt\"",1);
// execute_shell("\"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\wordpad.exe\" \"C:\Users\Erik\AppData\Local\Test_réseaux_sociaux\mesresultats.txt\"",1);
execute_shell("\"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\wordpad.exe\"",1);
game_end() // fin de partie !!!!!!!!!!!!!!!!!

2 pictures in attach files.

What do you think about that ?
Thanks.
Erik THIERRY
 

Attachments

S

Sam (Deleted User)

Guest
Edit: lol! I forgot escaping when I corrected you! my bad! XD I updated my post above with the correct code.

First, it's very unlikely anyone would want to install libre office in order to run your game or app.

Second, that is not the correct path to wordpad. It looks like you fused together the path to the exe with the path to the start menu shortcut.

Try this:

C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe

Also you are not using escaping on the backslashes like i do above, that's why libre office isn't opening either.

If you read the GMS2 manual it explains everything that has changed with referencing file paths and string character escaping:


These things are completely irrelevant to my extension. They are changes to GameMaker that no one pays attention to and I find half a dozen support tickets about the same thing consequently. But it's not your fault. I think yoyogames should've posted a blatant news article and emails to their subscribers warning about these changes so it would be more well known before the transition to GMS2, not after. I admit it is confusing to new users who aren't familiar with character escaping and it is hard to just expect users of the software to just automatically know when to check the docks for huge changes like this, it's unrealistic.

Hope this helps! And thank you for using the forums, but instead I wish more people would just message me on here, because people will look at the title and go "this is an extension support ticket and has nothing to do with GameMaker itself" and will likely ignore it.
 
Last edited by a moderator:
E

Erik131313

Guest
Hi,

Ok, my GMS2 runs good.
At the end of my GMS2 program, LibreOffice (or Wordpad) runs and opens the files mesresultats.txt. So, the students can see their results and print them.

with LibreOffice
execute_shell("\"C:\\Program Files\\LibreOffice\\program\\soffice.exe\" \"C:\\Users\\Erik\\AppData\\Local\\Test_réseaux_sociaux\\mesresultats.txt\"",1);

or with Wordpad
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" \"C:\\Users\\Erik\\AppData\\Local\\Test_réseaux_sociaux\\mesresultats.txt\"",1);

Now, I can finish my GMS2 program to my students for september.

Thank you very much for your help
Erik THIERRY
 
E

Erik131313

Guest
Hi,
I want use my program on the computers of my school. Each student have to open a session to use a computer. So the working directory change every time.

Is it possible to use :
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" \"working_directory\\mesresultats.txt\"",1);
instead :
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" \"C:\\Users\\Erik\\AppData\\Local\\Test_réseaux_sociaux\\mesresultats.txt\"",1);
Erik is the directory of the user Erik on my computer.
?
Thanks
Erik
 

chamaeleon

Member
Hi,
I want use my program on the computers of my school. Each student have to open a session to use a computer. So the working directory change every time.

Is it possible to use :
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" \"working_directory\\mesresultats.txt\"",1);
instead :
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" \"C:\\Users\\Erik\\AppData\\Local\\Test_réseaux_sociaux\\mesresultats.txt\"",1);
Erik is the directory of the user Erik on my computer.
?
Thanks
Erik
You can construct a string to pass as argument.
GML:
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" "  + working_directory + "\\mesresultats.txt\"");
 

Nidoking

Member
I think that's going to depend on the permissions set on the computer. If the user running the game doesn't have permission to your user directory, then no, they won't be able to run that and there's likely nothing you can do about it. If you have the permissions to install your game for all users, you should be able to put the text file in a public directory like C:/Users/Public. Then every user can access it.

EDIT: Ah, the point is to have each person's results in their own folder. Then yes, you can construct that command.
 
E

Erik131313

Guest
Thank you, but I still have the problem !

ok for this solution :
// Wordpad ok
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" \"C:\\Users\\Erik\\AppData\\Local\\Test_réseaux_sociaux\\mesresultats.t xt\"",1);

I obtain an error message, see attach file
// solution proposée par la communauté
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" " + working_directory + "\\mesresultats.txt\"",1);

I have add ,1 at the end.

an idea ?
Erik
 

Attachments

Nidoking

Member
My French is rusty, but I believe it's saying that it can't find the file in that directory. Are you sure you created the file using the same path? If you're creating it within the game, you'll also have to change the path where you create it to use working_directory, or just don't specify a path, because it should go into working_directory by default.
 
E

Erik131313

Guest
1ère solution
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" \"C:\\Users\\Erik\\AppData\\Local\\Test_réseaux_sociaux\\mesresultats.txt\"",1);
It's ok but the directory Erik is mine.

2ème solution
I obtain an error message, see attach file Capture.png (last message)
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" " + working_directory + "\\mesresultats.txt\"",1);

3ème solution
I obtain an error message, see attach file Capture 1.png
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" " + "\\mesresultats.txt\"",1);

I do not understand why the drive y: is used because the good way is : c:\Users\Erik\AppData\Local\Test_réseaux_sociaux\mesresultats.txt
Can I define in GMS2 the way for working_directory ?

Erik
 

Attachments

E

Erik131313

Guest
Hi,

Here is the creating the mesresultats.txt :

...
file_delete(working_directory + "\mesresultats.txt");
//
file = file_text_open_append(working_directory + "\mesresultats.txt");
file_text_write_string(file, global.nom+ " " + global.prenom + " " + global.classe);
file_text_writeln(file);
file_text_write_string(file, " Test réseaux sociaux");
file_text_writeln(file);
file_text_writeln(file);
file_text_close(file);
...
 

chamaeleon

Member
Hi,

Here is the creating the mesresultats.txt :

...
file_delete(working_directory + "\mesresultats.txt");
//
file = file_text_open_append(working_directory + "\mesresultats.txt");
file_text_write_string(file, global.nom+ " " + global.prenom + " " + global.classe);
file_text_writeln(file);
file_text_write_string(file, " Test réseaux sociaux");
file_text_writeln(file);
file_text_writeln(file);
file_text_close(file);
...
I'd suggest putting the entire computed filename in a local variable and use that variable in both the file open call and in show_debug_message() to ensure you know what is going on, and don't make any assumptions about the content or anything else.
 
S

Sam (Deleted User)

Guest
Thanks guys for helping out with my support tickets, lol. It really isn't my responsibility that anyone knows how to launch applications from the terminal or use existing gml functions, much less how GM handles escaping characters within strings now. But i get tons of tickets like that for my execute shell extension.

The problem appears that it could be a space in the working directory, always put file paths enclosed in quotes to avoid this.

In the code you posted above you only have the closing quote, you are missing the opening quote:
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" " + working_directory + "\\mesresultats.txt\"",1);

When it should be:
execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" \"" + working_directory + "\\mesresultats.txt\"",1);
 
E

Erik131313

Guest
Hi,
With : execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" \"" + working_directory + "\\mesresultats.txt\"",1);
I obtain an error message, see the joint file Capture.png.
The program is with the picture Capture1.png

From where is coming the drive y: in the error message ? I have only c: and d: as local drive.
If you have an idea...
Thanks
Erik
 

Attachments

Nidoking

Member
Ah, I assume that Y: is an internal drive mapping relating to the GMS sandbox. It points to the working directory artificially. You won't be able to get anywhere else on the hard drive using that path.
 
E

Erik131313

Guest
It's ok. No error message. Wordpad open the file.

execute_shell("\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\" \"" + game_save_id + "\\mesresultats.txt\"",1);

Thanks to all
Erik
 
Top