Skip to content

Commit 740af0f

Browse files
committed
Modified ArgumentsHandler::PrintProcessSettings() to also print command line arguments and also print the settings to an output file.
1 parent 7412ab8 commit 740af0f

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

test/ArgumentsHandler.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace shellanything
105105
return bRet;
106106
}
107107

108-
int PrintStatistics()
108+
int PrintProcessSettings(int argc, char **argv)
109109
{
110110
std::string process_path = ra::process::GetCurrentProcessPath();
111111
ra::process::processid_t process_id = ra::process::GetCurrentProcessId();
@@ -116,6 +116,10 @@ namespace shellanything
116116
std::string env_temp = ra::environment::GetEnvironmentVariable("TEMP");
117117
bool has_windows_write_access = CanAccessFolder("C:\\Windows", GENERIC_WRITE);
118118

119+
// print to the console
120+
printf("process.arguments.argc=%d\n", argc);
121+
for(int i=0; i<argc; i++)
122+
printf("process.arguments.argv[%d]=%s\n", i, argv[i]);
119123
printf("process.path=%s\n", process_path.c_str());
120124
printf("process.pid=%d\n", process_id);
121125
printf("process.current_dir=%s\n", process_current_directory.c_str());
@@ -125,6 +129,25 @@ namespace shellanything
125129
printf("env.temp=%s\n", env_temp.c_str());
126130
printf("has_windows_write_access=%d\n", (int)has_windows_write_access);
127131

132+
// print to a file
133+
FILE * f = fopen("shellanything_unittest.ProcessSettings.txt", "w");
134+
if (!f)
135+
return 1;
136+
137+
printf("process.arguments.argc=%d\n", argc);
138+
for(int i=0; i<argc; i++)
139+
fprintf(f, "process.arguments.argv[%d]=%s\n", i, argv[i]);
140+
fprintf(f, "process.path=%s\n", process_path.c_str());
141+
fprintf(f, "process.pid=%d\n", process_id);
142+
fprintf(f, "process.current_dir=%s\n", process_current_directory.c_str());
143+
fprintf(f, "process.architecture=x%d\n", process_architecture);
144+
fprintf(f, "process.elevated=%d\n", process_elevated);
145+
fprintf(f, "build.configuration=%s\n", build_configuration);
146+
fprintf(f, "env.temp=%s\n", env_temp.c_str());
147+
fprintf(f, "has_windows_write_access=%d\n", (int)has_windows_write_access);
148+
149+
fclose(f);
150+
128151
return 0;
129152
}
130153

test/ArgumentsHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace shellanything
3232
/// Print statistics about this program settings.
3333
/// </summary>
3434
/// <returns>Returns 0 when the function succeed. Returns a non zero values otherwise.</returns>
35-
int PrintStatistics();
35+
int PrintProcessSettings(int argc, char **argv);
3636

3737
} //namespace shellanything
3838

test/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ using namespace ra;
4444
int main(int argc, char **argv)
4545
{
4646
// Look for custom command line arguments
47-
bool has_printstatistics = ra::cli::ParseArgument("printstatistics", std::string(), argc, argv);
48-
if (has_printstatistics)
49-
return shellanything::PrintStatistics();
47+
bool has_PrintProcessSettings = ra::cli::ParseArgument("PrintProcessSettings", std::string(), argc, argv);
48+
if (has_PrintProcessSettings)
49+
return shellanything::PrintProcessSettings(argc, argv);
5050

5151
// Prepare Google's logging library.
5252
fLB::FLAGS_logtostderr = false; //on error, print to stdout instead of stderr

0 commit comments

Comments
 (0)