This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ComputerCraftFan11's profile picture

[1.31+] NeXuS Command Prompt (NOW RUNS .BAT FILES)

Started by ComputerCraftFan11, 17 May 2012 - 01:59 AM
ComputerCraftFan11 #1
Posted 17 May 2012 - 03:59 AM
This is my command prompt program, its supposed to simulate CMD/Batch (currently can't run batch files). This is the code:
Spoiler


local bExit = false

function eDecode(test)
local tCommandHistory = {}
test = io.open(test, "r")

for sLine in test:lines() do
table.insert( tCommandHistory, sLine )

local tWords = {}
for match in string.gmatch(sLine, "[^ t]+") do
table.insert( tWords, match )
end

eBatch(tWords, false, sLine)
end
test.close()
end

function eBatch(tWords, test, full)
local sCommand = tWords[1]
if sCommand == "echo" then
if tWords[2] then
print(string.sub(full, 6, string.len(full)))
if test == false then
print()
end
else
if test == false then
print("ECHO is on.")
end
end
elseif sCommand == "exit" then
bExit = true
elseif sCommand == "cmd" then
print("NeXuS Windows [Version 1.1.0001]")
print("Copyright (c) NeXuS Corporation. All rights reserved.n")
elseif sCommand == "pause" then
print("Press any key to continue.")
os.pullEvent("key")
sleep(0)
elseif sCommand == "cls" then
term.clear()
term.setCursorPos(1,1)
elseif sCommand == "dir" then
shell.run("rom/programs/list")
elseif sCommand == "del" then
if tWords[2] then
if fs.exists(tWords[2]) then
if fs.isReadOnly(tWords[2]) then
print("Could Not Find C:UsersAdmin" ..tWords[2].. "n")
else
fs.delete( tWords[2] )
end
else
print("Could Not Find C:UsersAdmin" ..tWords[2].. "n")
end
else
print("Could Not Find C:AppDataEarthUsersYouBrain.exen")
end
elseif sCommand == "execute" then --just made this one up, might not exist
if tWords[2] then
if fs.exists(tWords[2]) then
eDecode(tWords[2])
else
print("Could Not Find C:UsersAdmin" ..tWords[2])
end
end
elseif sCommand == "title" then
return tWords[2] --Title is pretty much useless here, so i'll just return what they typed for other's programs.
else
print("'"..sCommand.."' is not recognized as a internal or external command, operable program or batch file. n")
end
end

print("NeXuS Windows [Version 1.1.0001]")
print("Copyright (c) NeXuS Corporation. All rights reserved.n")

local tCommandHistory = {}
while not bExit do
write( "C:UsersAdmin> " )

local sLine = read( nil, tCommandHistory )
table.insert( tCommandHistory, sLine )

local tWords = {}
for match in string.gmatch(sLine, "[^ t]+") do
table.insert( tWords, match )
end

eBatch(tWords, false, sLine)
end

Click here for Formatted/Pastebin version

DO NOT run "execute" or the program will error.
These are the basic commands:

echo --Prints whatever you type
exit --Exits the prompt
cmd --Opens a new prompt
pause --Pauses until you press a key
cls --Clears the screen
dir --Lists all the files
del --Deletes the file (easter egg inside)
execute --Runs the files as a .bat (the program will error on .io in line 3 after you run it. this is a bug)
title --Changes the title of the prompt, doesn't do anything yet but return what u typed

I'm trying to make this be exactly like cmd (or do all the commands you can do)

Copyright (c) NeXuS Corporation. All rights reserved.
Is just to make it look more realistic since the real CMD has this.

Known bugs:
  • Echo doesn't support spaces, so this code won't work:
    
    echo HELLO EVERYONE
    
    , it will just echo HELLO
    Fixed.
  • The application crashes after you execute a .batch
ComputerCraftFan11 #2
Posted 19 May 2012 - 12:12 AM
Updated. This can now run .bat files and the echo not printing spaces fixed.
BrettSmith21 #3
Posted 27 May 2012 - 01:38 PM
can i use this in …OS its my os
ComputerCraftFan11 #4
Posted 27 May 2012 - 08:41 PM
can i use this in …OS its my os

OK, but make sure you give credit or post a link
Xemiru #5
Posted 26 June 2012 - 09:36 AM
Now why do I feel like this can be more of a danger to CC servers, being able to excecute BATCH files from a virtual computer inside a game.
Cloudy #6
Posted 26 June 2012 - 12:47 PM
Because you don't understand how this works. It doesn't execute bat files on the server. It executes files which run commands in the in game shell in order.
ardera #7
Posted 26 June 2012 - 06:53 PM
Hey what about
:thisisapoint
and
goto
support or
if
and
set
support?