Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6820345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:24:49+00:00 2026-05-26T21:24:49+00:00

I am writing a program to function as a testing plugin with a third

  • 0

I am writing a program to function as a testing plugin with a third party program. I have talked with the developer on the other end (don’t get me started) and he is using VB 6 to create a batch file and then calls the batch file using a shell command. His batch file is calling my plugin which I have written to output data to a file based on the parameters that I receive via his batch file.

My problem is that when his program calls the batch file via a shell command (again, he is using VB 6), my program executes and the console writelines that I put in place in front of and after the filestream stuff all execute, but the files are not created and therefore his program does not read the file I create (CP07.txt in this case). If I manually run the batch file from Windows explorer everything works as expected. I do have a process monitor capture if that is beneficial. The program is running as the local admin on a Win7 machine (although it is not elevated), UAC is disabled, there is no anti-virus software installed, and it is not writing to a root or system folder.

I appreciate any pointers. Since the ProcMon capture is long (1400+ lines), I have not posted it.

Regards,
S

Here is a sample batchfile from the other program…

  1. Full path to my exe
  2. Full path to the output file
  3. Parameter for my use
  4. Username
  5. Password

    C:\SpecifiedDir\myprogram.exe C:\Specified\Directory\CP07.txt parameter username password

I am overwriting the output file parameter as you can see because it did not work initially the other way (I think maybe something to do with the slashes being escaped or something) and I wanted to start with a simple and working program and then clean it up from there.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Plugin
{
class Program
{
    static void Main(string[] args)
    {
        Console.Write("Press any key to begin: ");
        Console.Write("Starting...", Console.ReadLine());
        //Console.WriteLine("Done");

        Console.WriteLine("Number of command line parameters = {0}",args.Length);
        for (int i = 0; i < args.Length; i++)
        {
            Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
        }
        Console.WriteLine("");

        TextWriter defaultOutputMethod = Console.Out;
        TextWriter defaultErrorOutputMethod = Console.Error;

        FileStream fStream;
        StreamWriter strWriter;

        FileStream fErrorStream;
        StreamWriter strErrorWriter;

        try
        {
            fStream = new FileStream("./Redirect.txt", FileMode.OpenOrCreate, FileAccess.Write);
            strWriter = new StreamWriter(fStream);
        }
        catch (Exception e)
        {
            Console.WriteLine("Cannot open Redirect.txt for writing");
            Console.WriteLine(e.Message);
            return;
        }
        try
        {
            fErrorStream = new FileStream("./RedirectError.txt", FileMode.OpenOrCreate, FileAccess.Write);
            strErrorWriter = new StreamWriter(fErrorStream);
        }
        catch (Exception e)
        {
            Console.WriteLine("Cannot open RedirectError.txt for writing");
            Console.WriteLine(e.Message);
            return;
        }

        Console.SetOut(strWriter);
        Console.SetError(strErrorWriter);

        Console.WriteLine("Number of command line parameters = {0}",            args.Length);
        for (int i = 0; i < args.Length; i++)
        {
            Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
        }

        // Store parameters into variables for reference
        string pSuccess = "OK";
        string pFail = "FAIL";
        string pOutputFile = args[0];
        string pLookupType = args[1];
        string pUserName = args[2];
        string pPassword = args[3];


        Console.SetOut(defaultOutputMethod);
        // Console.SetError(defaultErrorOutputMethod);

        strWriter.Close();
        fStream.Close();




        // Setup Commnet filestream and stream writer, and assign output to stream if file successfully created
        FileStream fCommnetStream;
        StreamWriter strCommnetWriter;
        string sCommnetOutputFile = @"./CP07.txt";
        try
        {
            fCommnetStream = new FileStream(sCommnetOutputFile, FileMode.OpenOrCreate, FileAccess.Write);
            strCommnetWriter = new StreamWriter(fCommnetStream);
        }
        catch (Exception e)
        {
            Console.WriteLine("Cannot open " + sCommnetOutputFile + " for writing");
            Console.WriteLine(e.Message);
            return;
        }
        Console.SetOut(strCommnetWriter);


        // Test Variables to determine output: Success or Failure
        string sSuccessPass = "1111";
        string sFailPass = "0000";

        if (pPassword == sSuccessPass)
        {
            Console.WriteLine(pSuccess);
        }
        else if (pPassword == sFailPass)
        {
            Console.WriteLine(pFail);
        }
        else
        {
            Console.WriteLine("OTHER");
        }

        Console.WriteLine("Output File: <" + pOutputFile + ">");
        Console.WriteLine("Lookup Type: <" + pLookupType + ">");
        Console.WriteLine("User Name: <" + pUserName + ">");
        Console.WriteLine("User Pass: <" + pPassword + ">");

        Console.SetOut(defaultOutputMethod);
        Console.SetError(defaultErrorOutputMethod);
        strCommnetWriter.Close();
        fCommnetStream.Close();

        strErrorWriter.Close();
        fErrorStream.Close();

        Console.Write("Press any key to finish: ");
        Console.Write("Ending...", Console.ReadLine());
        //Console.WriteLine("Done");
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:24:50+00:00Added an answer on May 26, 2026 at 9:24 pm

    I guess the problem is that you are writing into the “current directory”, which can be anything when your program is started by a batch file, which itself has been started by another application. It is not impossible that your files are written into the directory where the batch file resides 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing Classic ASP program.In one function, I have to use 2 update
I am writing a program that is meant to be extended by some function
Im writing a program that should read input via stdin, so I have the
I am writing a program to crawl the websites. The crawl function is a
I'm writing a program that among other things needs to download a file given
I'm writing a program in Common Lisp in which I need a function with
I am writing a program that will call a function from an external library,
I'm writing a program to access a bin packing algorithm function from a library,
I am writing a program in C++ where I need to call a function
Library liba defines a certain function f. When writing a C program that uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.