How do you make a MSDOS .com file? - operating-system

How do you make a .com file for MS-DOS? I have my own "operating system", PowerOS, and I want custom commands to be able to be entered. Is there any way to write a .com file?

The answer is fairly straightforward. You make a .COM file containing an MS/PC/DR-DOS program image by writing a program in a programming language and compiling it with a compiler that targets MS/PC/DR-DOS. That's it.
Don't get confused about filename extensions. There's a .COM program image file format, which is a fairly basic program image format. It was superseded by the "MZ" program image file format back in the 1980s. But it has nothing to do with the filename extension. A program image file for MS/PC/DR-DOS can have either the extension .COM or the extension .EXE, but the actual image file format is not dictated by this. (I mention DR-DOS. If memory serves correctly: In DR-DOS version 6 practically all of the program image files, even the ones named .COM, were actually "MZ" format executables, and compressed ones at that.)
What you do depends from what program image file formats your operating system's program loader is capable of understanding. And, really, only you can tell the world that. If your operating system's program loader understands the "MZ" executable file format, and the programs that run on your operating system are 16-bit and run in real mode, then compiling commands for your operating system is as simple (ignoring system call and library issues) as, say, cranking up OpenWatcom's 16-bit compiler+linker, wcl, and telling it to target MS/PC/DR-DOS with the -bcl=DOS option.
Of course, if your programs are 32-bit and your operating system runs them in protected mode, or even if your programs are 16-bit and your operating system runs them in protected mode, then the "MZ" file format will be unsuitable for your needs, and you should use one of the several alternative program image file formats.

I know that for windows 7 and most likely for the other windows OS's you can write either a .bat, .exe, or .com and place it into windows/system32 folder. That file can be used as a command from the command prompt by simply typing in the name of the command you made.
To take in command line parameters, a batch file can use the variables %1, %2, %3 etc. The command works like any other command and can be used to further write batch files with it.
As far as MS-DOS goes, you may be able to place one of those file types in the root directory or find where the other commands are placed and put it there. I am not sure if a COM file is required, but if so, there are batch to com converters out there such as this old school one:
Converter from batch to com

you can make an .bat file and paste this code to make custom commands
example:
#echo off
set /p command=
if %command% ==
in the code type your command at the end and what you will the command to do.
you can copy the if command to ad more commands

Related

Chrome sendNativeMessage with Batch, CMD or PowerShell

Google provides an example of calling native executables here. The actual "executable" is a .BAT file which calls python. I wanted to see if I could just run a .bat file with some typical OS or maybe even PowerShell commands. According to the help the executable needs to return UTF-8 JSON so I replaced the call to python with the following command:
TYPE %~dp0\SAMPLE.json
Where SAMPLE.json is a UTF-8 file with some JSON content.
Needless to say it does not work:
Error when communicating with the native messaging host.
According to the help it could be because of message size or text vs. binary output modes. I know of no way to get a batch file to "talk binary".
Is there any way to get Chrome to talk to text based CLI utilities like batch files, powershell...?

Execute batch file using dos()

I got a problem when executing batch file commands through matlab. This batch file includes commands to run simulations in Adams. When I execute the batch file directly from DOS window, it works well. But if I use matlab to execute it (using command dos()), it gives error saying 'cannot check out the license for Adams'.
This confuses me: if the license is incorrect, it should not work no matter I execute the batch file directly in DOS or ask MATLAB to execute it. I also tried to execute other DOS commands through matlab using dos() and it worked well.
Does anyone know what the problem may be?
Such issues are commonly caused by some environment variables being changed or cleared by MATLAB. I have very similar experience on Linux and Mac OS X, where this causes havoc when using system or unix.
In Unix-like systems, MATLAB is started from a shell script where all of this happens. So you can either incorporate missing variables there or in the .matlab7rc.sh in your home directory (the latter is preserved when you upgrade MATLAB and it is much easier to use). I won't go into all the Unix details here.
An alternative workaround is to explicitly set those variables when you issue a system command (e.g. system('export variable=value ; ...')). It is quite a bit of work, but you can then use that MATLAB code on different computers with ease.
On Windows, I'm not completely sure about the exact location of the corresponding files (and whether MATLAB starts in quite a similar way as on Unix). But if they exist, you can probably find it in the MATLAB documentation.
Anyhow, the alternative fix should work here as well.
First you need to diagnose which system variables you need (likely a PATH or anything that has a name related to Adams).
To do so in Windows, run set from the Windows command prompt (cmd.exe) and from within MATLAB. Whatever differs in the output is a possible suspect for your problem.
To inspect just a single variable, you can use the command echo %variablename%.
I will assume that you have found that the suspect environment variable is missing and should be set to value.
The workaround fix is then to run your command in MATLAB as system('set suspect=value & ...') where you replace ... with your original command.

Running a C++ program from an m.file

For a project I am working on I'm preparing data in MATLAB, then running the data through a separate external application (written in C++) named Model v2.exe, then performing further analysis with the output in MATLAB. I'm trying to create an M-file which does all of this, but I am struggling to get the C++ program to launch from my MATLAB code.
How can I launch an external application from within my MATLAB code?
You can either make use of the ! operator, or the system() command.
First, rename you application to something that has no spaces in the name, like modelv2.exe. Next, either make sure it is in the system path, as defined by your system environment variables, or generate a full path to it (eg: C:\Users\Phil\Desktop\modelv2.exe).
You can call an executable program from the command line using the exclamation point or the system command:
!modelv2
or:
!C:\Users\Phil\Desktop\modelv2.exe
will cause Windows to execute the program hello.exe if there is such a file in the current directory or on the system path. Alternatively:
system('modelv2');
or
system('C:\Users\Phil\Desktop\modelv2.exe');
will do the same thing.
References
"MATLAB Central - call and run an external program in matlab under windows", Accessed 2014-03-19, <http://www.mathworks.com/matlabcentral/answers/11568-call-and-run-an-external-program-in-matlab-under-windows>

How is a program in a specific location?

When writing a program, the program is sort of running in a particular directory which is the current working directory.
I'm trying to understand more about the idea of a cwd. How does a program know what its cwd is? Where is that information stored?
I know perfectly well how to use the os module in python, but I don't really understand what it means to have a cwd. Is it simply a data attribute, "this is where we are", that we can change arbitrarily? And we simply look for things and create things on that particular section of the HD? Or is some sort of pathway actually opening and closing actively when we change cwd, like a door getting shut and another being opened?
What happens on the computer when I change cwd in a program?
This may be language-agnostic, I am unsure.
The current working directory is (at least on most operating systems) an attribute of a process, so yes, it is more or less a simple attribute stating "this is where we are". As it's an attribute of a process, it is stored and managed by the OS kernel.
It can be changed arbitrarily by calling e.g. os.chdir in python, and a shell would similarly change its working directory each time you run the builtin cd command. And they both would normally call the same API of the operating system, e.g. chdir(). Changing the cwd is subject to filesystem permissions, so you can only change the working directory to a path that actually exists and you have permissions to.
The cwd may also be involved in file operations, as when a process opens a file path that is not an absolute path, the file name will be resolved relative to the cwd of the process.
On unix systems the cwd is inherited from the parent process, as such the cwd of a process you start from a shell will have its cwd to the directory you are in when you start the process (and not e.g. the directory of the executable you start).

CGI Script not responding through Wamp

I have configure wamp for cgi scripts correctly but it is not running following code and giving following server error on executing.
Bad file descriptor: don't know how to spawn child process:
C:/wamp/www/New folder/hello.cgi, referer: http://localhost/New%20folder/
My active perl is installed on C:/wamp/www/perl
here is code:
#!C:\wamp\bin\perl.exe -w
print "Hello World.\n";
Windows does not pay attention to #! lines. You need to make sure that your file extension (.cgi in your case, or .pl more commonly) is associated with your perl executable in the registry.
More info:
There are two ways to run a perl program/script, one is to execute perl directly with the file name of the main program/script as a parameter:
C:\wamp\bin\perl.exe mydir\myprog.pl
Don't ever do this in the cgi directory of your web server.
The other way to execute a program is to just name the file to be run and depend on the OS's built in method to find the right program to run it.
mydir\myprog.pl
On a *nix OS, the 1st two bytes of the file are analyzed to determine what to do with it, if those two bytes are the equivalent of the ASCII string #! then the file is treated as text, & the rest of the 1st line is read with the expectation that it will contain the path to the file's interpreter.
On a Windows OS, the file extension is used to search the registry for the path to the interpreter associated with that file type.