Skip to main content

I have a program that runs from the command prompt from my program.  This is the command: 

cmd.exe /C cscript //nologo D:\\NEW_MSI\\MSI_DATA\\MakeGuid.vbs > D:\\NEW_MSI\\MSI_DATA\\myguid.txt

I am using CALL "SYSTEM" USING WS-CMD-LINE to run the command. (the command above is placed in WS-CMD-LINE before the call to "SYSTEM".

The command works great from a dos prompt, but when I use it in my program - it does not work at all. The myguid.txt file is never generated. 

Does anybody have any suggestions on how I can get this to work? 

I have a program that runs from the command prompt from my program.  This is the command: 

cmd.exe /C cscript //nologo D:\\NEW_MSI\\MSI_DATA\\MakeGuid.vbs > D:\\NEW_MSI\\MSI_DATA\\myguid.txt

I am using CALL "SYSTEM" USING WS-CMD-LINE to run the command. (the command above is placed in WS-CMD-LINE before the call to "SYSTEM".

The command works great from a dos prompt, but when I use it in my program - it does not work at all. The myguid.txt file is never generated. 

Does anybody have any suggestions on how I can get this to work? 

Hi Amy,

I just tested this here using a very simple hello world script containing:

     WScript.Echo "Hello world!"

and the following program:

01 my-cmd pic x(100).
procedure division.

     move "cmd.exe /c cscript //nologo testit.vbs > hello.txt" to my-cmd
     call "SYSTEM" using my-cmd

and this worked fine.

Is your variable large enough to hold the command?


Hi Amy,

I just tested this here using a very simple hello world script containing:

     WScript.Echo "Hello world!"

and the following program:

01 my-cmd pic x(100).
procedure division.

     move "cmd.exe /c cscript //nologo testit.vbs > hello.txt" to my-cmd
     call "SYSTEM" using my-cmd

and this worked fine.

Is your variable large enough to hold the command?

Yes it is - it is 2000 characters long


Yes it is - it is 2000 characters long

And my directory that I am writing to has all the correct permissions (since I can run this command ang get a file in the dos prompt) 


Yes it is - it is 2000 characters long

If you remove the "> D:\\NEW_MSI\\MSI_DATA\\myguid.txt" does the command display its text to the console?


If you remove the "> D:\\NEW_MSI\\MSI_DATA\\myguid.txt" does the command display its text to the console?

No - it did not 


No - it did not 

Remove the //nologo option and see if it displays the cscript banner: On my system this is:

Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.


Remove the //nologo option and see if it displays the cscript banner: On my system this is:

Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

The program is not displaying a console screen at all -  I don't think the MakeGuid.vbs program is running with the CALL "SYSTEM".

the command works perfectly fine if I type it in myself on a command prompt screen.  


The program is not displaying a console screen at all -  I don't think the MakeGuid.vbs program is running with the CALL "SYSTEM".

the command works perfectly fine if I type it in myself on a command prompt screen.  

If it isn't displaying the banner then that means it isn't executing the cscript command itself. 

How are you compiling this program? I am compiling my test program as a native console application .EXE.


If it isn't displaying the banner then that means it isn't executing the cscript command itself. 

How are you compiling this program? I am compiling my test program as a native console application .EXE.

My program is not Native Code. We are running Visual COBOL with an WPF front end. All of our programs are in a project, and compiled together. 


My program is not Native Code. We are running Visual COBOL with an WPF front end. All of our programs are in a project, and compiled together. 

Try null terminating the command.

Example:

move Z"cmd.exe /c cscript //nologo testit.vbs > hello.txt" to my-cmd


Try null terminating the command.

Example:

move Z"cmd.exe /c cscript //nologo testit.vbs > hello.txt" to my-cmd

No - that did not work either - I still got the same results 


No - that did not work either - I still got the same results 

hmmm, that worked for me in a WPF application. If I didn't null terminate it, I actually received an index overflow RTS error and when I null terminated it the command ran successfully.

Can you run any command using call "SYSTEM?

For example, can use run the following:

cmd.exe /c dir *.* >mydir.lst


hmmm, that worked for me in a WPF application. If I didn't null terminate it, I actually received an index overflow RTS error and when I null terminated it the command ran successfully.

Can you run any command using call "SYSTEM?

For example, can use run the following:

cmd.exe /c dir *.* >mydir.lst

No, I cannot. I was able to before - this is what I find strange.  Could there have been an update to the NuGet packages I use, or something like that?

So It is for sure something to do with my software - but it might have something to do with Visual Studio???


No, I cannot. I was able to before - this is what I find strange.  Could there have been an update to the NuGet packages I use, or something like that?

So It is for sure something to do with my software - but it might have something to do with Visual Studio???

Can you try running the program outside of Visual Studio and see if it makes a difference? You might want to try to reboot your computer if you haven't already done so...


Can you try running the program outside of Visual Studio and see if it makes a difference? You might want to try to reboot your computer if you haven't already done so...

I'm going to have to write a new program to test that - all our programs in our software run from one exe - they all call each other.


I'm going to have to write a new program to test that - all our programs in our software run from one exe - they all call each other.

It only seems to be happening in my software when I use the CMD command - I have other programs in my software that use the "SYSTEM" command, and they are all working fine (I just tested them) 

This is really weird 

Could it be something to do with Visual COBOL 5.0?? That is the version I am on now - and I cannot upgrade at the moment - so that is not an option 


It only seems to be happening in my software when I use the CMD command - I have other programs in my software that use the "SYSTEM" command, and they are all working fine (I just tested them) 

This is really weird 

Could it be something to do with Visual COBOL 5.0?? That is the version I am on now - and I cannot upgrade at the moment - so that is not an option 

Try removing the cmd.exe /c

cscript is an executable so you shouldnt need the CMD when calling it thru system.


Try removing the cmd.exe /c

cscript is an executable so you shouldnt need the CMD when calling it thru system.

That did not work either  - Is there another way I can execute a a VBS (or any other program) outside of the software within Visual COBOL?


That did not work either  - Is there another way I can execute a a VBS (or any other program) outside of the software within Visual COBOL?

I am not sure what is going on with your system. It is as if the PATH is being corrupted?

Since you are using managed code you could run something like the following:

declare process as type System.Diagnostics.Process = new System.Diagnostics.Process
declare startInfo as type System.Diagnostics.ProcessStartInfo = new System.Diagnostics.ProcessStartInfo
set startInfo::WindowStyle = type System.Diagnostics.ProcessWindowStyle::Hidden
set startInfo::FileName = "cmd.exe"
set startInfo::Arguments = "/C cscript //nologo testit.vbs >testwpf.txt"
set process::StartInfo = startInfo
invoke process::Start


It only seems to be happening in my software when I use the CMD command - I have other programs in my software that use the "SYSTEM" command, and they are all working fine (I just tested them) 

This is really weird 

Could it be something to do with Visual COBOL 5.0?? That is the version I am on now - and I cannot upgrade at the moment - so that is not an option 

The following worked for me:

move z"cmd.exe /c dir *.* > mydir.lst" to my-cmd
call "SYSTEM" using my-cmd

move z"dir *.* > mydir.lst" to my-cmd
call "SYSTEM" using my-cmd

As Chris mentioned, you don't need the cmd.exe since SYSTEM launches a cmd.exe itself.


I am not sure what is going on with your system. It is as if the PATH is being corrupted?

Since you are using managed code you could run something like the following:

declare process as type System.Diagnostics.Process = new System.Diagnostics.Process
declare startInfo as type System.Diagnostics.ProcessStartInfo = new System.Diagnostics.ProcessStartInfo
set startInfo::WindowStyle = type System.Diagnostics.ProcessWindowStyle::Hidden
set startInfo::FileName = "cmd.exe"
set startInfo::Arguments = "/C cscript //nologo testit.vbs >testwpf.txt"
set process::StartInfo = startInfo
invoke process::Start

I would just add for all of these I believe cmd.exe is rather redundant since they all launch a cmd.exe under the covers


I am not sure what is going on with your system. It is as if the PATH is being corrupted?

Since you are using managed code you could run something like the following:

declare process as type System.Diagnostics.Process = new System.Diagnostics.Process
declare startInfo as type System.Diagnostics.ProcessStartInfo = new System.Diagnostics.ProcessStartInfo
set startInfo::WindowStyle = type System.Diagnostics.ProcessWindowStyle::Hidden
set startInfo::FileName = "cmd.exe"
set startInfo::Arguments = "/C cscript //nologo testit.vbs >testwpf.txt"
set process::StartInfo = startInfo
invoke process::Start

This worked Great for my calling of the VBS program, and when I do a DIR - but I am calling SHA256.exe - and once again, the command works great in a DOS command prompt, but not in the program either using CALL "SYSTEM" or  the code above. 

This is the command I am passing to the arguments: 

"D:\\NEW_MSI\\MSI_DATA\\SHA256.exe" "D:\\NEW_MSI\\MSI_DATA\\1094C_Request_TZQXR_20240319T181350000Z.xml" > "D:\\NEW_MSI\\MSI_DATA\\HR6C6ACA.TXT"


This worked Great for my calling of the VBS program, and when I do a DIR - but I am calling SHA256.exe - and once again, the command works great in a DOS command prompt, but not in the program either using CALL "SYSTEM" or  the code above. 

This is the command I am passing to the arguments: 

"D:\\NEW_MSI\\MSI_DATA\\SHA256.exe" "D:\\NEW_MSI\\MSI_DATA\\1094C_Request_TZQXR_20240319T181350000Z.xml" > "D:\\NEW_MSI\\MSI_DATA\\HR6C6ACA.TXT"

AH! I got it to work - I needed to add C/ START at the beginning of my command