[tip] Is it possible to run system command?

Ask questions about how to create a script or swap scripts with other users.
Post Reply
User avatar
pjj
Posts: 2109
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

[tip] Is it possible to run system command?

Post by pjj »

I would like to use echo, but perhaps other commands might be handy, too. I tried

Code: Select all

MainApp.RunApp("echo", "test > test.txt", true, true, 0);
but didn't get even error message, hence the question. (If it's not possible now, please treat it as a feature request.)
Last edited by pjj on 06 Oct 2013 12:12, edited 1 time in total.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
User avatar
pjj
Posts: 2109
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Is it possible to run system command?

Post by pjj »

pjj wrote:(If it's not possible now, please treat it as a feature request.)
Actually, it would be cool to use CMD commands in scripts, but I just figured out how to solve my script-related problem without using echo. Please move it down on your to-do list 8)
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
User avatar
pjj
Posts: 2109
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Yes, Virginia, it is possible to run system command

Post by pjj »

All you need to do is to add /c switch and enclose your argument list in parentheses, e.g.

Code: Select all

MainApp.RunApp("c:\\windows\\system32\\cmd.exe", "/c (echo Yes, you can call command line from a script!)", false, false);
If your argument is a file, of course you need to use double backslashes instead of single ones in its path, e.g.

Code: Select all

MainApp.RunApp("c:\\windows\\system32\\cmd.exe", "/c (del c:\\temp\\*.* /q)", false, false);
Please notice you can use variables as arguments, too:

Code: Select all

var filename = "readme.txt";
MainApp.RunApp("c:\\windows\\system32\\cmd.exe", "/c (del c:\\temp\\" + filename + ")", false, false);
Very truly yours,
Francis Pharcellus Church


(Would be helpful to add this to help file, I think.)
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
Post Reply