Run text file as command (cmd)

Gotruc Posted messages 17 Status Membre -  
Gotruc Posted messages 17 Status Membre -
Hello,

I don't know if this question has already been asked, but since I couldn't find an answer, I'm asking my question here.

I would like to know how to execute the contents of a text file as a command.

I know that you can do this by entering the content of the file as a variable and then executing it afterwards:
set /p command= <"text file"
%command%

But is there a simpler way?

3 réponses

dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   5 656
 
bonjour
copy fichier.txt fichier.bat & fichier
3
kxgeneration Posted messages 737 Registration date   Status Membre Last intervention   39
 
Change simply the extension of your .txt file to .bat, double click on it and it will run like a charm :)

.txt => .bat
0
Gotruc Posted messages 17 Status Membre 1
 
Yes, I know, but would it be possible to do it without having to create a batch file?
0
kxgeneration Posted messages 737 Registration date   Status Membre Last intervention   39
 
It's impossible to execute a .txt file as such!!!!
After that, you can possibly create a PowerShell script that does the same thing and compile it into an .exe, the same goes for C#.

What code do you actually want to execute? Post it, and I'll see if similar functions exist in PS.
0
Gotruc Posted messages 17 Status Membre 1
 
I don't really have any example code or usage, but I wasn't thinking of executing the txt file itself (I know that's impossible) but executing its content. However, according to the responses in this topic, it seems impossible (except for the solution I mentioned in my question).
0
sabrinebou22
 
I don’t know, sorry.
-1