Disclaimer: Cygwin is a Linux emulator in Windows. Cygwin is not in the supported platform list. This article is meant as a self-help resource for customers with the similar issues.
In this issue, there are several things to understand to find the right solution:
1. The 'system' function of MATLAB only passes the command to the operating system (OS) and has no control over how the passed command is executed.
2. Installing Cygwin does not grant the OS the knowledge to the counterpart executables of the Linux commands. These executables reside under the 'bin' sub-directory under the Cygwin installation directory.
3. Forward slash ('\') works for Windows shell but not for the Cygwin shell.
4. Two single quotes ('''') do not act as a double quote ('"') in the Windows shell.
5. The semicolon (';') works as a pipeline in Cygwin (or real Linux) but not in a Windows shell.
With the above understanding, the code in the question should be revised as below. The primary change is to include the full paths to each invoked Cygwin commands.
>> clear;
>> cygwinPath = 'C:\cygwin\bin';
>> cw_gzip = fullfile(cygwinPath, 'gzip');
>> cw_sed = fullfile(cygwinPath, 'sed');
>> cw_split = fullfile(cygwinPath, 'split');
>> cw_date = fullfile(cygwinPath, 'date');
>> inputfname = 'input.gz';
>> nlines = 5;
>> outprefix = ''
>> system(cw_date);
>> pipeline = sprintf(...
>> ['%s -dc %s | '...
>> '%s -n \"2p;4~2p\" | ' ...
>> '%s -a 3 -d -l %d --numeric-suffix=1 --additional-suffix=%s '...
>> '--filter=\"%s > $FILE.gz\" - %s/file'], ...
>> cw_gzip, name2, ...
>> cw_sed, ...
>> cw_split, nlines, '_r2_callqual.txt', ...
>> strrep(cw_gzip,'\','/'),...
>> outdir);
>> system(pipeline);
>> system(cw_date);
Best Answer