0

Let's assume that there are no command-line arguments. How do you pass input data to a program?

I'm thinking you'd write the input to a file with a specific name, such that the program knows to open and read it as input. However, how would one discover the name of that file? Usually, running a command-line program without arguments or with some standard help argument (e.g. \?) produces some instruction on how to use it. But given an environment with no command-line arguments, how does one discover how to operate a program?

8
  • Not programmers related. Not sure this is even a stackoverflow question. Most probably a better fit for superuser.comCommentedMar 19, 2012 at 13:20
  • 2
    Stackoverflow FAQ said "Professional programmers interested in conceptual questions about software development, ask on Programmers.". Isn't this a conceptual question about software development?
    – Core Xii
    CommentedMar 19, 2012 at 13:24
  • 1
    @karlphillip - there's no code. It's a design question.
    – ChrisF
    CommentedMar 19, 2012 at 13:29
  • 1
    @karlphillip: It is certainly not a reverse engineering question. It's about operating system design, actually.
    – Core Xii
    CommentedMar 19, 2012 at 13:38
  • 1
    Do you need to understand how an existing program is doing this? Do you need to do something like that and you want to get some tips?CommentedMar 19, 2012 at 13:42

8 Answers 8

2

You can use tools to display all the hardcoded strings inside the application, and hopefully the filename will show up.

Check OllyDBG on Windows and strings on Linux (it's a cmd-line application).

A more complex solution: fire up your favorite asm debugger (OllyDBG, GDB) and get your hands dirty.

2
  • Ah yes, one could read the program file and it could contain a standard header with this information. Though that somewhat postpones the issue - somehow you must then discover that standard.
    – Core Xii
    CommentedMar 19, 2012 at 13:27
  • 2
    The idea is to dump all the strings in the program. This can display a lot of interesting information, and one of those could be name of the file he is looking for.CommentedMar 19, 2012 at 13:29
1

In the .NET world, this is achieved with the use of an app.config file included with your source code. This is copied to the output folder with a name following the convention "MyApp.exe.config" where your application is "MyApp.exe".

I don't know if there are similar conventions for other languages.

4
  • A standardized, human-readable, self-documenting file describing the program's operation, supplied with it. Also known as a manual. Funny that didn't occur to me.
    – Core Xii
    CommentedMar 19, 2012 at 13:43
  • I'm not sure what you're saying. I've not described the manual in the answer.
    – RichardM
    CommentedMar 19, 2012 at 14:10
  • Well, that's the idea you gave me anyway. What I got from your answer was that there's some other, standardized file supplied with the program that hints to its operation one way or another.
    – Core Xii
    CommentedMar 19, 2012 at 14:22
  • The app.config file contains the application settings that are your inputs. Here's a link with more details and samples: generally.wordpress.com/2007/09/27/…
    – RichardM
    CommentedMar 19, 2012 at 14:45
1

Popular convention seems to be for programs to use standard streams for stuff like that:

In computer programming, standard streams are preconnected input and output channels between a computer program and its environment (typically a text terminal) when it begins execution...

You can see how it works using whatever command interpreter is available in your OS. In Windows, you may launch DOS shell and type help. In Unix you launch shell and type man.

4
  • Yes indeed. Though, without command-line arguments, there are no pipes, and as such, standard I/O would likely not be present as it'd be somewhat useless.
    – Core Xii
    CommentedMar 19, 2012 at 13:49
  • @CoreXii you may want to clarify your question pointing out that no standard I/O is expected to be used, either
    – gnat
    CommentedMar 19, 2012 at 13:54
  • It's not that it isn't expected. If it's the best solution, it's certainly valid. But given that pipes don't exist, I'd explore others first.
    – Core Xii
    CommentedMar 19, 2012 at 13:58
  • 1
    @Core Xii: Mistaken assumption. There is no reason to presume that pipes exist only in the presence of command lines. Win32 on Win95 is an obvious counter-example. It did have pipes, but not CMD.EXE (the 32 bits command line).
    – MSalters
    CommentedMar 19, 2012 at 15:01
1

You could look at COM, as implemented by Microsoft. In that system, the OS loads your DLL into memory when someone needs an object of your type. If anyone needs to pass information to that object, it can use the standard IUnknown::QueryInterface(GUID) method to obtain an well-known interface, and then pass information via that interface.

Of course, if your object doesn't have such an interface, it'd return E_NO_INTERFACE. But that's no different (just eassier to debug) than a CLI program ignoring its arguments.

    1

    Many Operating Systems already have the concept of "environment variables". This is a set of named values that are passed to every process, in addition to the command line arguments. Using C, you'd access them with getenv().

    Similar to the /? convention for command lines, the OS writer can define a convention that the presence of a HELP variable in the environment means that a program should show usage information. In C code: if (getenv("HELP")) { ShowHelp(); }

      1

      I don't quite understand what the OP is really asking, but it is fairly common for command line programs to use environmental variables as inputs in lieu of command line parameters.

      Of course that begs the question of where did the environmental variables come from.

        0

        You can create .bat file with your arguments in it.

          -1

          I'm going for a straight-man answer.

          You read the user's manual. Then you use some sort of input device like a keyboard or mouse to control the program. If the program requires a large amount of data, you can direct it to a file. Directing a program to a file has varied widely through the ages, but has standardized to OS typical popup windows.

          If it's a command line program, with no command line arguments, then you are dependent on the program's interface. At some point you probably have to type in the path to the file name.

          2
          • And how would you use such a program from another program? It must be usable without user intervention.
            – Core Xii
            CommentedMar 19, 2012 at 22:18
          • @CoreXii, That'd be a great detail to add to the question.
            – Philip
            CommentedMar 20, 2012 at 14:10

          Start asking to get answers

          Find the answer to your question by asking.

          Ask question

          Explore related questions

          See similar questions with these tags.