Do not open DOS Shell when running X command

Reply
Super Contributor
Posts: 418

Do not open DOS Shell when running X command

Hello everyone. Does anyone know if there is an option in SAS to NOT open the command line dos shell when running an X command, or a %sysexec command?

For example, say I wanted to un-zip 100 folders, and each one took ~5 minutes of un-zip time (due to size of data).  It would be impossible to run this program in SAS on a computer, and still type on that computer, because every time the command line DOS Shell opens your typing is moved to that prompt location.

This basically implies you should never run these programs on a computer you are actively using... Which I understand and I can just run it on a different computer, but I was curious if there was an option to avoid this.

An example of the code I am trying to run is

%sysexec "c:\Program Files\7-zip\7z.exe" x "c:\drive\ABC.zip" -O"c:\drive\Newfolder" -y;

Thanks!

Respected Advisor
Posts: 3,786

Re: Do not open DOS Shell when running X command

I "always" use INFILE PIPE FILEVAR=COMMAND for execution of OS commands, no DOS box is just one advantage.

Sometime I like SYSTASK COMMAND but I can't remember if it flashes a DOS box or not.  I don't think so.

Respected Advisor
Posts: 3,156

Re: Do not open DOS Shell when running X command

It seems to me that "systask command" opens NO windows. I prefer this one over X command for more control and return code.

Haikuo

Super User
Super User
Posts: 7,706

Re: Do not open DOS Shell when running X command

IMO I am not fond of running commands out to system from SAS, so the way I would go about it is to create a batch file with the unzips and run that, hence leaving SAS free to do other things.  For example: http://stackoverflow.com/questions/17077964/windows-batch-script-to-unzip-files-in-a-directory

Super User
Posts: 19,063

Re: Do not open DOS Shell when running X command

What about the noxwait option?

The dos shell will open but will close when it's done.

SAS(R) 9.2 Companion for Windows, Second Edition

Super Contributor
Posts: 418

Re: Do not open DOS Shell when running X command

Thanks for the noxwait option, but unfortunately this code loops over 10,000 files and each takes ~1 second so basically every time I try to work on the computer I lose control every 1 second, and then gain it back for a milisecond and then lose it, etc.. So in this case that doesn't help much unfortunately. Thanks for the advice tho!

  This is actually a step within a much much bigger sas ETL program that I wrote.  So I can't have it happen until other steps occur, and then many many other steps need to happen after it.   Because of this I am not sure if your solution works to be honest... If I am mid-understanding please let me know.

  I will test this. I have never heard of the "systask command" to be honest, so I have no idea what that does. I will keep you posted with what I find.

@data_null_; can you explain what your example is using an actual example of say "opening the notepad" application?  I am not sure exactly how I would use what you are saying, but will try to do some more research.

Respected Advisor
Posts: 3,786

Re: Do not open DOS Shell when running X command

Using your SYSEXEC as an example it goes like this.  I can't test this I'm not using windows but it does the same thing as SYSEXEC in that it executes the command and sends any stdout to the program as INFILE.  If there is not any stdout that's OK it still executes.  You can execute more than one COMMAND by looping, reading from SET, etc.  Experiment with this and see what you think.

data _null_;
  
length command $128;
   command =
'"c:\Program Files\7-zip\7z.exe" x "c:\drive\ABC.zip" -O"c:\drive\Newfolder" -y';
  
do while(not eof);
      infile dummy pipe filevar=command end=eof;
      input;
     
putlog _infile_;
      end
  
run;
Super Contributor
Posts: 418

Re: Do not open DOS Shell when running X command

I"m struggling to get the systask syntax correct. Can anyone re-write this %sysexec command using systask? it doesn't seem to work no matter how I try the quoting...

%sysexec "c:\Program Files\7-zip\7z.exe" x "I:\Projects\Brandon\zip test\TestZip.zip" -O"I:\Projects\Brandon\zip test\zip test output" -y;

Since only parts of the line are quoted I am curious as to how to put this into the systask command call

Respected Advisor
Posts: 3,786

Re: Do not open DOS Shell when running X command

try single quotes.  or quote function  %sysfunc(quote("c:\Program Files\7-zip\7z.exe" x "I:\Projects\Brandon\zip test\TestZip.zip" -O"I:\Projects\Brandon\zip test\zip test output" -y))

Super User
Posts: 19,063

Re: Do not open DOS Shell when running X command

What about SAS ODS Package instead to create a zip file?

Using SAS and ODS PACKAGE to create ZIP files - The SAS Dummy

Super User
Super User
Posts: 7,706

Re: Do not open DOS Shell when running X command

Unfortunately, as far as I am aware currently the ODS Package only supports creating ZIPs, not unpacking them.  Pkware has only been around since 1986, so we have to give them some time to catch up :smileysilly:

In response to what I was talking about above, it depends on your setup however I am talking about removing the unpacking part from your ETL, and having the unpacking part done directly on the OS.  So (I assume everything here):

You get lots of files sent to you and save them in c:\temp overwriting all the ones currently there as you are using version control.

You then run a batch program which is a text file, with .bat, and is located in c:\temp along with pkunzip.exe.

This runs over each file in c:\temp unzipping every .zip file into a subfolder \output.

You then have an ETL job which runs later on and looks at the unpacked data in c:\temp\output

So the point being SAS does not do any unpacking, only utilizes the unpacked data.

Respected Advisor
Posts: 3,786

Re: Do not open DOS Shell when running X command

What is the error?  Show the log.  I think you will need wait option to.

Super Contributor
Posts: 418

Re: Do not open DOS Shell when running X command

Unfortunately no. The code runs, it produces the log, but nothing happens.

I'm actually not sure if the command is just not passing correctly, or not working once passed, etc..  Sorry if I didn't make that clear enough.

Super User
Posts: 9,867

Re: Do not open DOS Shell when running X command

Why not make a batch file ( .bat ), and run it just once ,No sas interference .

Super Contributor
Posts: 418

Re: Do not open DOS Shell when running X command

Truthfully I'm just not a fan of the .bat file methodology, because you are now running two independent programs that are not linked.   I would have to first run the .bat file, and then call the sas program... I could probably call the sas program from the .bat file, but now I also have to learn how to script the program already written into a .bat file.

If this is the only way I understand and that's probably what I will end up doing, I am just curious if there is a 'better' way, if that makes sense.

Ask a Question
Discussion stats
  • 20 replies
  • 674 views
  • 1 like
  • 7 in conversation